Board index » cppbuilder » directory trees

directory trees


2004-04-13 02:40:41 AM
cppbuilder101
hi,
i was writing my own installer program for my app, but i ran into a
roadblock.i need to copy over directory trees which contains both files and
directories. i am using pure win32 (no OWL or MFC) and there is no
CopyDirectory (). there is a CopyFile (), but the tree that i want to copy
has a lot of files and i don't want to do it that way. plus when i add a
file to the tree i wil have to remember to update the intstaller. i was
wondering if there is a good way to do this? the only other way i could
think of was to spawn a new process and call xcopy to do the directory copy.
any ideas?
aloha,
mike
 
 

Re:directory trees

While ShFileOperation might be able to do a deep copy of everything in
a directory tree that is when it copies from one place on the disk to
another. It does not accept a list of things to create.
The underlying operating system has no facilities for creation of the
set of items. Each directory and each file is individually created.
It is a reasonably easy task to cycle through and create each.
Just make a set of functions or a class which scans a directory tree
and assembles the file and directory names along with the file sizes.
Make a copy of that set of functions and have it create that same set.
Now you not only have the creation function but you also have
something that will automatically add the new file you've put into the
original directory tree to the list it finds.
. Ed
Quote
mike wrote in message
news:407ae2f1$ XXXX@XXXXX.COM ...

i was writing my own installer program for my app, but
i ran into a roadblock.i need to copy over directory trees
which contains both files and directories. i am using pure
win32 (no OWL or MFC) and there is no CopyDirectory ().
there is a CopyFile (), but the tree that i want to copy
has a lot of files and i don't want to do it that way. plus
when i add a file to the tree i wil have to remember to
update the intstaller. i was wondering if there is a good
way to do this? the only other way i could think of was
to spawn a new process and call xcopy to do the
directory copy. any ideas?
 

Re:directory trees

Mike:
I suggest you to take a look at Inno Installer: www.jrsoftware.org
It solves the most case of installation (even includes presets for typical
setups, ie: BDE, VBS, and others).
If you need more control it allows to call a DLL or use InnoScript (a Delphi
based language).
Inno was choiced with several awards and by last but no least: it's free.
Saludos
Sebastian
"mike" < XXXX@XXXXX.COM >escribi?en el mensaje
Quote
hi,

i was writing my own installer program for my app, but i ran into a
roadblock.i need to copy over directory trees which contains both files
and
directories. i am using pure win32 (no OWL or MFC) and there is no
CopyDirectory (). there is a CopyFile (), but the tree that i want to copy
has a lot of files and i don't want to do it that way. plus when i add a
file to the tree i wil have to remember to update the intstaller. i was
wondering if there is a good way to do this? the only other way i could
think of was to spawn a new process and call xcopy to do the directory
copy.
any ideas?

aloha,
mike


 

{smallsort}

Re:directory trees

"mike" < XXXX@XXXXX.COM >wrote in message
Quote
hi,

i was writing my own installer program for my app, but i ran into a
roadblock.i need to copy over directory trees which contains both files
and
directories. i am using pure win32 (no OWL or MFC) and there is no
CopyDirectory (). there is a CopyFile (), but the tree that i want to copy
has a lot of files and i don't want to do it that way. plus when i add a
file to the tree i wil have to remember to update the intstaller. i was
wondering if there is a good way to do this? the only other way i could
think of was to spawn a new process and call xcopy to do the directory
copy.
any ideas?
You have already received a couple of good suggestions, but if you still
want a function to copy whole directories, I have a set of functions that I
wrote a long time ago to do just that:
bool CopyTree( char *SourceDirectory, char *TargetDirectory );
bool DeleteTree( char *SourceDirectory, bool bEraseReadOnlyFiles = false );
bool MoveTree( char *SourceDirectory, char *TargetDirectory, bool
bMoveReadOnlyFiles = false );
Let me know if you are interested in having these, and I will gladly post
them to the attachments newsgroup. They are written entirely with the Win32
API (no VCL) because they were written for VC++. I also found the code
below with a google search. It's Delphi, but it would be a fairly easy port
to C:
function CopyTree(dir, dest: string): Boolean;
var
sfos: TSHFileOpStruct;
begin
FillChar(sfos, SizeOf(sfos), 0);
dir := dir + '\*.*'#0;
dest := dest + '\*.*'#0;
with sfos do begin
wnd := 0;
wfunc := FO_COPY;
pFrom := PChar(dir);
pTo := PChar(dest);
fFlags:= FOF_ALLOWUNDO or FOF_RENAMEONCOLLISION or
FOF_SIMPLEPROGRESS;
fAnyOperationsAborted := false;
hNameMappings := nil;
lpszProgressTitle := nil
end;
Result := SHFileOperation(sfos) = 0
end;
- Dennis
 

Re:directory trees

Dennis,
That would be a tremendous help. could you please post it?
Aloha,
mike
"Dennis Jones" < XXXX@XXXXX.COM >wrote in message
Quote

"mike" < XXXX@XXXXX.COM >wrote in message
news:407ae2f1$ XXXX@XXXXX.COM ...
>hi,
>
>i was writing my own installer program for my app, but i ran into a
>roadblock.i need to copy over directory trees which contains both files
and
>directories. i am using pure win32 (no OWL or MFC) and there is no
>CopyDirectory (). there is a CopyFile (), but the tree that i want to
copy
>has a lot of files and i don't want to do it that way. plus when i add a
>file to the tree i wil have to remember to update the intstaller. i was
>wondering if there is a good way to do this? the only other way i could
>think of was to spawn a new process and call xcopy to do the directory
copy.
>any ideas?

You have already received a couple of good suggestions, but if you still
want a function to copy whole directories, I have a set of functions that
I
wrote a long time ago to do just that:

bool CopyTree( char *SourceDirectory, char *TargetDirectory );
bool DeleteTree( char *SourceDirectory, bool bEraseReadOnlyFiles =
false );
bool MoveTree( char *SourceDirectory, char *TargetDirectory, bool
bMoveReadOnlyFiles = false );

Let me know if you are interested in having these, and I will gladly post
them to the attachments newsgroup. They are written entirely with the
Win32
API (no VCL) because they were written for VC++. I also found the code
below with a google search. It's Delphi, but it would be a fairly easy
port
to C:

function CopyTree(dir, dest: string): Boolean;
var
sfos: TSHFileOpStruct;
begin
FillChar(sfos, SizeOf(sfos), 0);
dir := dir + '\*.*'#0;
dest := dest + '\*.*'#0;
with sfos do begin
wnd := 0;
wfunc := FO_COPY;
pFrom := PChar(dir);
pTo := PChar(dest);
fFlags:= FOF_ALLOWUNDO or FOF_RENAMEONCOLLISION or
FOF_SIMPLEPROGRESS;
fAnyOperationsAborted := false;
hNameMappings := nil;
lpszProgressTitle := nil
end;
Result := SHFileOperation(sfos) = 0
end;

- Dennis


 

Re:directory trees

"mike" < XXXX@XXXXX.COM >wrote in message
Quote
Dennis,

That would be a tremendous help. could you please post it?

Aloha,
mike
Done.
- Dennis
 

Re:directory trees

Mahalo Dennis!!
"Dennis Jones" < XXXX@XXXXX.COM >wrote in message
Quote
"mike" < XXXX@XXXXX.COM >wrote in message
news:407c31e0$ XXXX@XXXXX.COM ...
>Dennis,
>
>That would be a tremendous help. could you please post it?
>
>Aloha,
>mike

Done.

- Dennis