• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 795
  • Last Modified:

Error in creating bat file.

Hi,
I have created a bat file as in the snippet below, and saved it as c:\xcopy.bat.

I want the file to copy updated PDFs from a network drive to the PC and log which files have been transferred.  When I copy and paste the code into a command window, it runs fine, and I get the log file I want.  However when I save the .bat file and try to run it, she screen fills up with the message "The Process cannot access the file because it is being used by another process" and the log file comes out as attached.

Any help as to why the bat file is not working properly would be appreciated.
echo ******************** >> copylog.txt
echo Copy Started on %DATE% %TIME% >> copylog.txt
echo ******************** >> copylog.txt
XCOPY "X:\SHOPS POS\PDF" "C:\Documents and Settings\Administrator\Desktop\PDF" /D /Y /Z >> copylog.txt
echo ******************** >> copylog.txt
echo Copy Finished on %DATE% %TIME% >> copylog.txt
echo ******************** >> copylog.txt

Open in new window

copylog.txt
0
nauthencharge
Asked:
nauthencharge
  • 2
  • 2
1 Solution
 
sirbountyCommented:
Do not save it as xcopy.bat
xcopy is already a valid command in your path...rename it and retry (call it myxcopy.bat if you'd like)
0
 
nauthenchargeAuthor Commented:
Brilliant, Thanks!
0
 
sirbountyCommented:
Happy to help - thanx for the grade! :^)
0
 
HubasanCommented:
Hi nauthencharge,

Two things here:
1) Rename your BAT file to something other than "xcopy" since that is reserved for XCopy utility used by windows.
2) place backslash at the end of the copy destination path. Below is your corrected code you can use:

echo ******************** >> copylog.txt
echo Copy Started on %DATE% %TIME% >> copylog.txt
echo ******************** >> copylog.txt
XCOPY "X:\SHOPS POS\PDF" "C:\Documents and Settings\Administrator\Desktop\Config\" /D /Y /Z >> copylog.txt
echo ******************** >> copylog.txt
echo Copy Finished on %DATE% %TIME% >> copylog.txt
echo ******************** >> copylog.txt

Open in new window

0
 
HubasanCommented:
ooops, to late...hehehe...sirbounty is fast man!
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now