Backup Folders with subfolders and all files inside.

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Knoore
Junior Coder
Posts: 28
Joined: Fri Oct 20, 2006 8:30 am

Backup Folders with subfolders and all files inside.

Post by Knoore » Fri Apr 13, 2007 9:59 am

VBSTART
Function GetFolderList(folderspec)
Dim fso, f, f1, fc, s, sf
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.SubFolders
For Each f1 in fc
s = s & f1.name & ";"
sf = GetFolderList(folderspec & "\" & f1.name)
if sf "" then
s = s & f1.name & "\" & sf & ";"
end if
Next
If s dd
Month>mm
Year>yyyy
Let>date=%yyyy%%mm%%dd%
//Init
Let>APP_TITLE=Backup By Knoore
Let>msg_finished=The Backup is finished.%CRLF%The program will now be closed.
Let>todisk=F:\
MidStr>WIN_DIR,1,3,fromdisk
//Dirs
Let>fromdir=%fromdisk%Documents and Settings\%USER_NAME%\
Let>todir=%todisk%backups\%date%\
//Setup info
Let>oldpath[1]=%fromdir%Desktop\test\
Let>newpath[1]=%todir%test\
Let>pathamount=1

//Start
Let>pathnr=1
Repeat>pathnr
Let>pathold=oldpath[%pathnr%]
Let>pathnew=newpath[%pathnr%]
IfDirExists>pathold
GoSub>execute
Endif
Let>pathnr=pathnr+1
Until>pathnr>pathamount
MessageModal>%msg_finished%

SRT>execute
//Files in Folder
Let>copytopath=pathnew
Let>copyfrompath=pathold
GoSub>copyfiles

//Files in SubFolders
VBEVAL>GetFolderList("%pathold%"),folderList
Separate>folderList,;,folders
If>folders_count>0
Let>d-cntr=0
Repeat>d-cntr
Let>d-cntr=d-cntr+1
Let>subfolder=folders_%d-cntr%
Let>copyfrompath=%pathold%%subfolder%
Messagemodal>copyfrompath
Let>copytopath=%pathnew%%subfolder%
GoSub>copyfiles
Until>d-cntr,folders_count
Endif
END>execute

SRT>copyfiles
Run>cmd.exe /c mkdir %copytopath%
Run>cmd.exe /c copy %copyfrompath% %copytopath%
END>copyfiles


goto>end
//IfDirExists>%fromdir%Favorites\
// Let>oldpath[1]=%fromdir%Favorites\
// Let>oldpath[2]=%fromdir%My Documents\
// Let>oldpath[3]=%fromdir%Desktop\
// Let>newpath[1]=%todir%Favorites\
// Let>newpath[2]=%todir%My Documents\
// Let>newpath[3]=%todir%Desktop\
//Else
// Let>oldpath[1]=%fromdir%Favorieten\
// Let>oldpath[2]=%fromdir%Mijn Documenten\
// Let>oldpath[3]=%fromdir%Bureaublad\
// Let>newpath[1]=%todir%Favorieten\
// Let>newpath[2]=%todir%Mijn Documenten\
// Let>newpath[3]=%todir%Bureaublad\
//Endif
//Let>outlookbackup=%dir%Local Settings\Application Data\Microsoft\Outlook\Outlook.pst
label>end
I got the following dirs in the folder test:
test\Copy of New Folder\New Folder\New Folder\New Folder\
test\New Folder\

If i run the script, it works untill here: test\Copy of New Folder\New Folder\
After that the sub dir aint 1. but 2., because of a bug in the vbscript
1. Copy of New Folder\New Folder\New Folder\
2. New Folder\New Folder\
This is a script i found here in the forums. It works perfect for 2 dir deep sub dirs, but if you have more dirs it will malfunction.

Can someone please help me fix the script?

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Apr 13, 2007 3:42 pm

I don't know off hand how to fix the script you've discovered. What I suggest instead is try the VBScript or the DOS method discussed in this thread. I use this and have never had any problems.

Edit- I see I misread the issue. Sorry for any confusion.
Last edited by JRL on Tue Apr 17, 2007 12:36 pm, edited 1 time in total.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Fri Apr 13, 2007 5:05 pm

I haven't read all the code, but have you overlooked using DOS xcopy /s?
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Knoore
Junior Coder
Posts: 28
Joined: Fri Oct 20, 2006 8:30 am

Post by Knoore » Fri Apr 13, 2007 6:40 pm

Run>cmd.exe /c xcopy %pathold%*.* %pathnew%*.* /s

If pathold or pathnew containt a " " [SPACE] nothing happens, if the pathold and pathnew dont contain a " " [SPACE] it works perfect.

How to make it work with the " " [SPACE] ?

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Fri Apr 13, 2007 6:58 pm

Put " " around the paths should work.


Run>cmd.exe /c xcopy "%pathold%*.*" "%pathnew%*.*" /s
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
Captive
Macro Veteran
Posts: 213
Joined: Sun Oct 20, 2002 8:37 pm
Location: Colorado, USA

Post by Captive » Mon Apr 16, 2007 11:23 pm

You used QUOTE instead of CODE, so certain lines of your code did not appear properly;
Example:

Code: Select all

If s <then>dd
Also - I don't see an "End Function" for the GetFolderList routine.

If you're interested, I'd recommend checking out the VBScript Method "CopyFolder". Something roughly similar to;

Function Blah(MySource, MyDest)
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFolder(MySource, MyDest)
End Function

Then you'd pass your source and dest path's;
Such as: Source being: "c:\mydocuments\letters\*"
And Destination being "c:\tempfolder\"
(If destination ends in \ then it assumes the path already exists. If it does not, it will create it).


Just so you're aware - there are apparently issues with xcopy in regards to how it deals with different "long filenames" that have the similar "short filename" values.

One place I just googled for this issue describes it as follows;
The problem with XCOPY has to do with the potential corruption of the short (8+3) file names for files and directories where there are instances of multiple long names that begin with the same first 7 characters. What happens is that the long names are preserved okay but the short names are regenerated for the destination files. So a file may end up with a different short name (8+3) on the new drive than it had on the original drive.
While generally this won't make any difference, it could impact applications that would be using the original "shortfilename" value.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Mon Apr 16, 2007 11:41 pm

The xcopy problem that was mentioned by Captive is well documented on the site for XXCOPY at this link: http://www.xxcopy.com/xxcopy03.htm

I have used XXCOPY for many years to overcome that problem.

Freeware info from http://www.xxcopy.com:
# XXCOPY Freeware is available for personal (non-commercial) use.
# XXCOPY Freeware is primarily for stand-alone computers.
# XXCOPY Freeware supports nearly all XXCOPY Pro features.
Some advanced features for networks are made available as demonstration.
I use Macro Scheduler with XXCOPY on many systems for nightly backups. It is a command line application with more switches than you will find in any other program, but the documentation is very thorough. A real nice option is the ability to use an Exclude switch
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts