I have this code:
xcopy c:\files1\test1 c:\files2\test2
What in situation when I don't know first location? - xcopy c:\***\test1 c:\files2\test2
How I can define first location in code?
I have this code:
xcopy c:\files1\test1 c:\files2\test2
What in situation when I don't know first location? - xcopy c:\***\test1 c:\files2\test2
How I can define first location in code?
If you know the name of the file you can search for that file in the parent location (first location) and then get it's location and then copy it to another drive. To get the location of the file you can search it from CMD by
dir filename.ext /s /p (in case you don't know the filename then you can search by .ext and if you don't know it's ext then you can search it by filename . Also if it is a folder than you don't need .ext only filename).
You don't need anything about variable% cd. What you need is that you run a command in for loop and do a copy command for each loop. For this you can create a batch file like this:-
or
As you said that "the .bat file is in the folder with the files to be copied" you would need the cd\ (cd/ works fine both ways) command to get to the parent drive and search for the files with the wildcards I provided above and then if search is okay it will copy that file to the specified folder one by one. Also there is a drawback that the batch file needs to be in that drive you need the files to search in for although the copy location can be on any drive provided it's online. For eg. if you have the batch file inside D drive you can only use this method on D drive and not C drive as the command prompt works on a single drive.