Jump to content
xisto Community
Sign in to follow this  
malssllp

Bat File Copying Within The Same Folder

Recommended Posts

I've used the .\ in the past to copy a file that is in the same folder as my bat file successfully however for some reason this time its not working unless I put in the entire source path. Any suggestions?

Bat file simply says:

xcopy /d .\"filename.xml" "C:\Program Files\Vendor Name\Application Name" /s /y
I've also tried:
xcopy /d .\"filename.xml" "C:\Program Files\Vendor Name\Application Name\filename.xml" /s /y
However, if I put:
xcopy /d "networkfileshare\folder\filename.xml" "C:\Program Files\Vendor Name\Application Name" /s /y
things work fine however we are moving in a different direction and require things to work from the same folder without the file share.

Share this post


Link to post
Share on other sites

Hi!Back in the age of command-line DOS, xcopy was a really useful utility. Some developers used it as an installer through a batch file though they had to include the xcopy executable as some systems didn't have the utility.Judging by the working path that you've provided, I'd say that the you have the networkfileshare directory in your current path. Unless filename.xml is in your current path, you cannot use ".\filename.xml" to refer to the file. You can, however, refer to the file with a ".\networkfileshare\folder\filename.xml". Alternatively, before issuing the xcopy command, you can type "cd networkfileshare\folder" and then type the xcopy command with the ".\filename.xml".Additionally, I would like to suggest avoiding the ".\" because those are two extra characters and omitting them doesn't really make a difference. Besides, when you double-click a batch file in Windows or run the batch file by CD-ing to the directory and then typing the batch file name, you are executing the batch file within the context of the directory in which it is located. If somebody were in a different directory and were running your batch file by specifying the absolute path, I'd be surprised - it's possibly, but I can't think of why anybody would intentionally do such a thing. I understand you are trying to cover all of your bases and make your batch file execution 'fool-proof', but it's a very improbable occurrence. You are actually typing two additional characters to clarify that the file you are referring to is in the current directory but because you are passing a filename and not executing a program (which could be located elsewhere, depending on the path variable), it is implicitly understood that the file is located in the current directory.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.