Sign in with
Sign up | Sign in
Your question

Calling Batch files

Last response: in Applications
Share
January 28, 2012 8:09:24 AM

Hi, I am wanting to make a batch file that copies another batch file to all folders inside a directory and then runs them (copying to unknown user folders on my customer's hard drives to delete temp files and copy e-mail files and address books etc., so the username variables are not available), i have this line which copies the batch file into every directory:
for /R %%i in (.) do copy "%CD%\copyme.bat" "%%i"

but i am having trouble calling each of the batch files, when i do i get a ".\" in the middle of each, for example if i use for /R %%i in (.) do call "%%i\copyme.bat it tries to run c:\test\1\.\copyme.bat instead of c:\test\1\copyme.bat.

how do i remove the .\ from the variable or is there another way to do this? unfortunately as this will run on many different hard drives taken from many different computers before backing up and reinstalling windows, each time the user folders will be different plus sometimes there will be multiple users. There is no point in backup up temp Internet files, temp folder and other junk, so i want to delete it before copying, since i do this several times in a day it will save much time. i just made a Windows folder cleanup and used it on a customer's 85GB Backup and without deleting anything useful like system32 and inf, etc i managed to get the backup down to 30GB and saved copying all those files and folders, now i am working on the batch file for cleaning up User folders but since it's a variable i need to solve the problem in a different way.
thanks

More about : calling batch files

a b L Programming
January 30, 2012 12:12:31 PM

Why do you need to write and execute batch files in each directory when you are already traversing the file system with your main batch?

If the hard drive you are attempting to back up is on it's last legs unnecessary file writes are the last thing you should be doing.

There are any number of backup solutions available. Anything worth it's salt will have a file type / directory pattern exclusion feature.
m
0
l
January 30, 2012 2:09:31 PM

All good, sorted it out with:

@if exist %CD%\docume~1 dir "%CD%\documents and settings" /o:n /a:D  /b > g:\customer\%input%\Users.txt
@if exist %CD%\Docume~1 set UserOS=XP
@if exist %CD%\users dir "%CD%\users" /o:n /a:D  /b > g:\customer\%input%\Users.txt
@if exist %CD%\users set UserOS=Vista

then for each item i wanted to delete:
@If %UserOS%==Vista (for /f "delims=~" %%V in (g:\customer\%input%\Users.txt) do (if exist "Users\%%V\Microsoft\Search" rd /s /q "Users\%%V\Microsoft\Search"))

didn't need to use multiple batch files

Of course junctions need to be unlinked first to stop it getting confused about documents and settings for Vista/7 installs
m
0
l
!