This should work for you if there are no PST files under c:\backuppst to begin with.
@echo off
for /f "delims=" %%i in ('dir /s /b /a-d \*.PST') do xcopy "%%~i" "c:\backuppst%%~pi"
pause
Question
I need to find all *.PST file on my "C" drive, and copy all instance to a new folder on C:\
How to do this in dos-batch with keep the original structure? I don't want to override the second instance the first one..
for /f "delims=" %%i in ('dir /s /b /a-d *.PST') do copy /b "%%~i" "C:\backuppst"
As you suggested I use Xcopy:
Xcopy c:*.pst c:\backuppst /i/h/s/y /Exclude:my.txt
In my.txt I have: C:\backuppst
But I got "cannot preform cycling copy"
Solution 2
This should work for you if there are no PST files under c:\backuppst to begin with.
@echo off
for /f "delims=" %%i in ('dir /s /b /a-d \*.PST') do xcopy "%%~i" "c:\backuppst%%~pi"
pause
OTHER TIPS
try this:
for /f "delims=" %%i in ('dir /s /b /a-d c:\*.PST^|findstr /ivc:"C:\backuppst"') do copy /b "%%~fi" "C:\backuppst"
Use the xcopy
command, it can do this in one go, without needing for
.
It supports the parameter /exclude
, which lets you exclude specific files or folders, like your backup directory.