can i return to previous location with cmd?

February 11, 2011 at 06:41:27
Specs: Windows 7, 4gb

Ive got a batch file and it is run from My documents or Desktop or well anywhere where the user will copy it. Now what I want it to do is make a new directory on the home drive and then copy a *.doc file from its current location to the new directory. The problem I am having, is that when the new folder is created on the home drive, it cant copy the file from where the *.bat file was launched.

Ive got this code:
mkdir User
copy *.doc c:\User\

but the *.doc file is in the same folder as the *.bat and then *.bat cant find the file specified.

See More: can i return to previous location with cmd?

Report •

February 11, 2011 at 06:47:41
I took your code save the .bat to my desktop, placed a .doc in the root, and then ran the logic and it worked successfully.

Is your .bat in the root then?

Report •

February 11, 2011 at 06:50:48
no it is not. the bat file will be on lets say 30 other computers and i wont know where they will copy it. it may be in documents or on desktop or in my music or wherever. and then this is where the problem appears. if everyone copied it into their root it would be much easier but i dont know where they are going to copy it to

Report •

February 11, 2011 at 07:10:51
What about

MKDIR C:\User\
COPY C:\*.doc C:\User\

Under the assumption that the drive letter C:\ is associated with every machine.

Report •

Related Solutions

February 11, 2011 at 07:58:28
Have a look at the "pushd" and "popd" commands. I think they will solve your problem. (Although, as tcerveny points out, you don't really have a problem; but these commands can be useful in more complex situations.)

Report •

February 11, 2011 at 08:38:38
@tcerveny thanks for your reply's, it gave me a new insight on my next job.
@ijack thanks to you, I have completed this batch file completely :D.
thanks to both of you for your help and insight. It's much appreciated

Report •

Ask Question