1.

Solve : How to write a batch file to copy directories recursively and then create a shor?

Answer»

Hi there,
I need to create a batch file which can perform following actions.
1.Copied directories and sub directories from source folder OLDER than 10 days to destination
folders.
2. Delete copied directories from source folder and create short cuts for that in source folder.
I have written the following batch file. But I am not getting proper result which I want.

@echo off
@echo copying file to Archive folder
XCOPY c:\tempMovetoUDrive U:\Archive /e/d:03/20/2012
pause
@echo creating a SHORTCUT for copied files
set SHORTCUT_NAME=Shortcut to copied files
set SHORTCUT_PATH=C:\tempMovetoUDrive
set PROGRAM=U:\Archive
set WORK_DIRECTORY=C:\tempMovetoUDrive
set ICON_FILE=%SYSTEMROOT%\system32\SHELL32.dll
set ICON=4
set WINDOW_STYLE=1
echo SET oWS = WScript.CreateObject("WScript.Shell") > tempshortcut.vbs
echo sLinkFile = "%SHORTCUT_PATH%\%SHORTCUT_NAME%.lnk" >> tempshortcut.vbs
echo SET oLink = oWS.CreateShortcut(sLinkFile) >> tempshortcut.vbs
echo oLink.TargetPath = "%PROGRAM%" >> tempshortcut.vbs
echo oLink.IconLocation = "%ICON_FILE%, %ICON%" >> tempshortcut.vbs
echo oLink.WindowStyle = "%WINDOW_STYLE%" >> tempshortcut.vbs
echo oLink.WorkingDirectory = "%WORK_DIRECTORY%" >> tempshortcut.vbs
echo oLink.Save >> tempshortcut.vbs
WScript.exe tempshortcut.vbs
rem del tempshortcut.vbs

Any help would be appreciated.
Many thanks
Contrary to popular belief, XCOPY does not do file aging. If the /d switch is present, files dated on or after the /d switch date are copied. A solution might be ROBOCOPY where you can age the files and maintain the directory structures.

You can get ROBOCOPY here

The shortcut CODE looks OK, but I did not test it, just made sure the batch code transferred into the VBS code correctly.




Discussion

No Comment Found