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..

  • I think this should work, but I need to keep the original subdirectory or take every hit to a unique subdirectory?
  • I have to exclude the c:\backuppst directory from search
 for /f "delims=" %%i in ('dir /s /b /a-d *.PST') do copy /b "%%~i" "C:\backuppst" 

Edit

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"

Was it helpful?

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top