Reputation: 2751
I am using robocopy to copy certain files from a long hierarchy-ed folder structure. E.g.: *.properties
files. They may reside in very deep level of the directory structure (e.g. C:\a\v\b\g\f\aa.properties
). Now I want to copy these properties files to another keeping only the top most parent folder (e.g.: destination folder structure will be a\aa.properties
); I have used /S
option to do so but it includes the parents too.
Below is the batch file I've tried:
@echo off
::Author = SHUBHENDU
echo Copying files from %1 to %2
set source=%1
set destination=%2
set list=abc def
(for %%a in (%list%) do (
echo Copying files from %%a
ROBOCOPY %source%\%%a %destination%\%%a *_en.properties /S
))
Source directory (sample):
F:.
│ temp.bat
│
└───ss
├───asd
│ ss_en.properties
│
└───asdfsdsd
│ aa_en.properties
│
├───dd
│ asdsa.txt
│
└───ff
ff_en.properties
Required destination directory:
F:.
├───asd
│ ss_en.properties
│
└───asdfsdsd
aa_en.properties
ff_en.properties
Upvotes: 1
Views: 1381
Reputation:
You have to make sure the source is not the same as the destination.
NOTE!!! I have not recreated your scenario, so this is untested, just amended your code. I will fix the code based on your errors.
@echo off
set source=%1
set destination=%2
for %%F in (%destination%) do set destination="%%~fF"
for /r %source% %%F in (.) do if "%%~fF" neq %destination% ROBOCOPY %source%\%%F %destination%\%%F *_en.properties /S
Upvotes: 0