How to create batch file to move folders recursively?

April 5, 2012 at 08:29:46
Specs: Windows 7
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
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

@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

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

See More: How to create batch file to move folders recursively?

Report •

June 27, 2012 at 13:59:09
what is it doing and what would you like the response to be?

:: mike

Report •

June 27, 2012 at 18:22:21
If your .lnk settings are static, why not just keep a copy of it and copy it instead of having the batch write a wscript to build the link each time? If the shortcut's details change (f/e a date-based directory), then you would need to re-build the shortcut.
I tested a version of your code on my xp and it worked fine.
Other than that, the only thing I would suggest is to set local, so that you don't interface with the global environment vars (often unintended and disruptive, since global var. values override any settings in your batch - this has driven me nuts more than once!) Make line 1 to:
@echo off & setlocal

(ps, this never happened before to me, a .vbs runs without explicitly invoking wscript/cscript! when did that feature evolve? before, I always had to use c/wscript.)

Report •

Related Solutions

Ask Question