Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: SHFileOperation duplicates folders into subfolders



Permlink Replies: 2 - Last Post: Mar 21, 2017 2:22 AM Last Post By: pss edn
pss edn

Posts: 45
Registered: 1/13/04
SHFileOperation duplicates folders into subfolders
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 20, 2017 1:43 AM
I am using the following code to make a backup of a folder from the hard disk to an USB.
The first time, all folders and subfolders are created in the USB i dos not exist, but for subsecuent copies, a subfolder is created, and from now on, allways the second subfolder is used
That is:

First time in the USB:
H:\SOMEFOLDER\DAY12

Subsecuent times in the USB:
H:\SOMEFOLDER\DAY12\DAY12

After Googling, and making variatios of this code, I can not get that the correct copy will be allways into H:\SOMEFOLDER\DAY12

var
tsfo: TSHFileOpStruct;

begin
sSrcPath := 'C:\SomeFolder\Day12';
sDestPath := 'H:\SomeFolder\Day12;

FillChar(tsfo, SizeOf(tsfo), #0 );
with tsfo do
begin
Wnd := Self.Handle;
wFunc := FO_COPY;
pFrom := pChar(sSrcPath + #0);
pTo := pChar(sDestPath + #0);
fFlags := FOF_NOCONFIRMATION + FOF_NOCONFIRMMKDIR + FOF_NOERRORUI;
fAnyOperationsAborted := 0;
end;
try
SHFileOperation(tsfo);
except
end;

Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: SHFileOperation duplicates folders into subfolders
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 20, 2017 4:11 AM   in response to: pss edn in response to: pss edn
El 20/03/2017 a las 09:43, pss edn escribió:
I am using the following code to make a backup of a folder from the hard disk to an USB.
The first time, all folders and subfolders are created in the USB i dos not exist, but for subsecuent copies, a subfolder is created, and from now on, allways the second subfolder is used
That is:

First time in the USB:
H:\SOMEFOLDER\DAY12

Subsecuent times in the USB:
H:\SOMEFOLDER\DAY12\DAY12

After Googling, and making variatios of this code, I can not get that the correct copy will be allways into H:\SOMEFOLDER\DAY12

var
tsfo: TSHFileOpStruct;

begin
sSrcPath := 'C:\SomeFolder\Day12';
sDestPath := 'H:\SomeFolder\Day12;

FillChar(tsfo, SizeOf(tsfo), #0 );
with tsfo do
begin
Wnd := Self.Handle;
wFunc := FO_COPY;
pFrom := pChar(sSrcPath + #0);
pTo := pChar(sDestPath + #0);
fFlags := FOF_NOCONFIRMATION + FOF_NOCONFIRMMKDIR + FOF_NOERRORUI;
fAnyOperationsAborted := 0;
end;
try
SHFileOperation(tsfo);
except
end;


Try this:

var
   tsfo: TSHFileOpStruct;
   sFrom, sTo: String;
begin
   sSrcPath := 'C:\SomeFolder\Day12';
   sDestPath := 'H:\SomeFolder';  // Parent folder where Day12 should be copied
 
   ForceDirectories(sDestPath); // Be sure sDestPath folder exists
 
   sFrom:= sSrcPath + #0;  // Use local variables to store the
   sTo:= sDestPath + #0;   // double-null terminated string
 
   FillChar(tsfo, SizeOf(tsfo), #0 );
   with tsfo do
   begin
     Wnd := Self.Handle;
     wFunc := FO_COPY;
     pFrom := pChar(sFrom);
     pTo := pChar(sTo);
     fFlags := FOF_NOCONFIRMATION + FOF_NOCONFIRMMKDIR + FOF_NOERRORUI;
     fAnyOperationsAborted := 0;
   end;
   try
     SHFileOperation(tsfo); // SHFileOperation doesn't throw exceptions
   except                   // so the try..except block is unnecesary
   end;


Edited by: Antonio Estevez on Mar 20, 2017 4:13 AM
pss edn

Posts: 45
Registered: 1/13/04
Re: SHFileOperation duplicates folders into subfolders
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 21, 2017 2:22 AM   in response to: pss edn in response to: pss edn
Hello Antonio,

This did the trick, thanks for your help.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02