I am using robocopy to copy certain files from a long hierarchy-ed folder structure. Eg: *.properties
files. They may reside in very deep level of the directory structure (eg 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 (eg: 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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.