dos - How can I copy a particular file from a source directory to a destination directory while recreating the folder structure -


i have use batch . destination folder should have copied file along directory structure of source directory (for file copied only). example :

source: c:\folder1\folder2\folder3\text1.txt destination: c:\backup

after command executed destination folder should : c:\backup\folder1\folder2\folder3\text1.txt

i must use command c:\ (root directory) . in source there multiple files name ="text1.text" ,but different folder structure. want "text1.txt" copied path providing (source), , not files named "text1.txt" [this can achieved using--- xcopy source\text1.txt* destination /s /y].please help.

@echo off setlocal :: command alone accomplish task using xcopy :: i'm changing directorynames suit system :: xcopy c:\sourcedir\a\b\text1.txt u:\backup\sourcedir\a\b\ :: :: or leave last xcopy out , batch same :: if supply parameter "c:\sourcedir\a\b\text1.txt" :: :: ie. @ prompt, enter :: :: thisbatchname "c:\sourcedir\a\b\text1.txt" :: :: (where quotes optional unless parameter contains  ::  special character or space" :: xcopy "%~1" "u:\backup2%~p1" 

the first xcopy should obvious.

the second works using %~1 first parameter, minus enclosing quotes (if any) - requoted ensure character string produced parsed single string.

the second parameter xcopy strings u:\backup2 %~p1 - p - path of parameter 1, quote whole thing.

consequently, command executed "c:\sourcedir\a\b\text1.txt" parameter be

xcopy "c:\sourcedir\a\b\text1.txt" "u:backup2\sourcedir\a\b\" 

which creates destination tree required.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -