Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
shadowulf
- Posts: 2
- Joined: 06 Nov 2012 10:30
#1
Post
by shadowulf » 06 Nov 2012 10:33
Ok I need some help here, I am about ready to scream!!!
I need a batch file that does the following and for the life of me I cannot seem to get it to work.
Searches the entire C:\ drive for all *.PST files
Copies these files to a network drive location (j:\@PCBackup\PST)
If more than one file exists with the same name, rename instead of overwrite
So if the following exists:
c:\archive.pst
c:\user\archive.pst
the output would be something like:
j:\@PCBackup\PST\archive1.pst
j:\@PCBackup\PST\archive2.pst
Is this possible??
HELP !!
Thank you !!
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#2
Post
by foxidrive » 06 Nov 2012 10:41
Untested:
Code: Select all
@echo off
for /f "delims=" %%a in ('dir c:\*.pst /b /s /a-d') do call :next "%%a"
goto :EOF
:next
set c=
:loop
if exist "j:\@PCBackup\PST\%~n1%c%%~x1" set /a c=c+1 & goto :loop
echo copying %1 to "j:\@PCBackup\PST\%~n1%c%%~x1"
copy /b "%~1" "j:\@PCBackup\PST\%~n1%c%%~x1"
goto :EOF
-
shadowulf
- Posts: 2
- Joined: 06 Nov 2012 10:30
#3
Post
by shadowulf » 06 Nov 2012 10:51
I'd buy you a pint if I could
Works great....Thank you !!