Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 490
  • Last Modified:

Batch file to copy a file

Please tell me how I can create a .bat file that copies a file "example.txt" from C:/Folder1/Example.txt to C:/Folder2/Example.txt

Thanks!
0
dshrenik
Asked:
dshrenik
4 Solutions
 
loki_lokiCommented:
create a text file and enter

copy "C:/Folder1/Example.txt"  "C:/Folder2/Example.txt"

save it with .bat extension and that will do it.

Other parameters like overwritting etc can be found by opening a command prompt and typing copy /?
0
 
NotVeryFatCommented:
xcopy /c /q /y "c:\folder1\example.txt" c:\Folder2\
0
 
dshrenikAuthor Commented:
It says "the system cannot find the file specified". My folder name has spaces. Does tht matter?
I am actually overwriting the file. Can you include the relevant parameters for the batch file?
Thanks!

@NotVeryFat:
Can you please describe what the parameters mean? Thanks!
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
NotVeryFatCommented:
To get round the spaces issue, put the whole name in quotes e.g. "c:\This folder\That folder\File name.txt"
0
 
dshrenikAuthor Commented:
I do have it in quotes.
0
 
ccwill88Commented:
In DOS Command mode use
echo copy c:\folder1\example.txt  c:\folder2 >copyfile.bat

Open in new window

0
 
NotVeryFatCommented:
/c continues copying if errors occur - handy if you're doing a whole load of copying, one problem file won't cause the whole lot to fail
/q quiet - doesn't show the file names as they copy
/y surpresses prompting if running as a batch

you don't necessarily need any of the above, they just make things run better.

You can simply create a .bat file and add the following line:

xcopy "c:\folder1\example.txt" "c:\folder2\"
0
 
dshrenikAuthor Commented:
xcopy seems to work fine (just "copy" didn't)
It asks me if I want to overwrite the file. How can I make it overwrite by default?

Thanks!
0
 
LHT_STCommented:
add /y on the end

if you open up a command prompt and type xcopy /?

it will list all the switches you can add to the command to enable things like no prompting etc.
0
 
dshrenikAuthor Commented:
It now says "Access denied". Could it be because I'm copying into "Program Files (x86)"?
0
 
NotVeryFatCommented:
Possibly. You'll need to check the permissions on the folder you're copying into, that the account you're using has at least "write" privileges.
0
 
dshrenikAuthor Commented:
Well, I'm the administrator on the computer. I think it works if I right click on command prompt and say "Run as admin". Can i do something similar with a batch file?
0
 
NotVeryFatCommented:
You can either right click Command Prompt and 'Run As' or right click your batch file and 'Run As'
0
 
dshrenikAuthor Commented:
Is it possible to do that by default, on a simple double click of the .bat file?
0
 
NotVeryFatCommented:
You can use third party software to run batch files as another user (ie cpau.exe) or you can create a scheduled task and tell it to run the process as a different user. Then just run the scheduled task rather than double clicking the batch file...

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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