0

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?

3
  • @rubesum and what do you mean by "I don't know the firs location" Does that mean that you need to get the location from the user? Jan 2, 2014 at 17:26
  • What "code" are you referring to? Are you writing some script or what?
    – jtheman
    Jan 2, 2014 at 17:27
  • I have bat file that copies another file. User download a bat file and I do not know where it gets. On this script I must determine initial locations. But how to do it when I do not know the initial location?
    – rubesom
    Jan 2, 2014 at 17:40

1 Answer 1

0

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

1

or

2

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.

1
  • If I know the name of the file to be copied, and the bat file is in the folder with the files to be copied, is there any other way? I read something about the fact that the location is stored in the variable% cd. But I totally do not know how to deal with it.
    – rubesom
    Jan 2, 2014 at 18:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .