How can copy a folder(located in the location of batch file)containing another folders and files to another location using batch file...
i am trying using command below but not working..
xcopy /E /Y %~p\DagwoodLoki#hp.com\* C:\Loki
Please help me
I dont know what "%~p" does but i think that following should work
xcopy %~p\DagwoodLoki#hp.com\ C:\Loki /E /Y
the /E and /Y must be written later the source and the target.
Maybe this?
xcopy /E /Y "%~dp0\DagwoodLoki#hp.com\*" C:\Loki
%~dp0 is substituted with drive+path to the batch file, without quotes, if any.
Related
I am trying to make a .bat file that will copy another batch file to the windows start up directory. but XCOPY keeps saying it is missing parameters, can you have a look at my code and see where I'm going wrong.
xcopy "c:\Desktop\CHAOSCOPY.bat" *.* "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\"
xcopy "c:\Desktop\CHAOS V2.bat" *.* "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\"
xcopy "c:\Desktop\CHAOS.bat" *.* "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\"
xcopy syntax is
xcopy sourcedecription destinationdescription
(disregarding any switches)
What is your code supposed to do? Is "c:\Desktop\CHAOSCOPY.bat" a file you want to copy? If so, copy it to where? What has *.* got to do with the matter? It specifies all files with an extension. Do you want to copy all files with an extension from the current directory and also "c:\Desktop\CHAOSCOPY.bat" to the destination? If so, you need two separate xcopy commands. cmd cannot read your mind - it can't tell which of the three parameters is source and which destination.
I want a .bat file that will copy all files and folders from one folder to another folder automatically. For example:
robocopy "c:\source" "D:\target" /e /MON:1 /xc /xn /xo
However I need it so that once a file has been copied, that file will not be copied again, even if the copy has been moved to a different directory. Is there any way to do this? Is it possible for robocopy to create a log and check against that before copying the file?
If robocopy can't do it, what can?
Use additionally the option /M on your robocopy (SS64 article) command line as suggested by Stephan because this option results in copying only files with archive attribute set in source folder tree and removing archive attribute by robocopy after successful copying the file.
%SystemRoot%\System32\robocopy.exe "C:\source" "D:\target" /M /E /MON:1 /XC /XN /XO
The archive attribute is automatically set again on file modification.
You could perhaps also use xcopy (SS64 article):
%SystemRoot%\System32\xcopy.exe "C:\source" "D:\target\" /M /E /C /I /Q /G /H /R /K /Y >nul
Important for your task is again option /M for copying only files with archive attribute set in source folder tree and clearing the archive attribute after copying the file.
Note: /I works without user prompt only with target folder path ending with a backslash.
Run in a command prompt window robocopy /? respectively xcopy /? for details on the other options or read the Microsoft documentations for robocopy and xcopy.
Alright So, the easiest way to do this is to copy each
file and folder individually, to said folder.
This may not be what you are looking for, but
I hope it helps! Sadly there is no way to
copy l files folders with a single command.
I need to be able to create a bat script to do 3 things:
Search for multiple specific filenames in a directory.
Find the most recently generated version based on each filename specified.
Copy that most file to a new dir.
I am very new to coding in general, so any assistance would be much appreciated.
So far all I have been able to do is figure out how to copy files from one location to another using the below:
xcopy /s c:\source\differentfilename1.csv d:\target\
xcopy /s c:\source\differentfilename2.txt d:\target
xcopy /s c:\source\differentfilename3.html d:\target
So far I have tried the following and its not copying the files over:
ECHO
CD D:\Data\
MKDIR D:\Data\CopyFilesHere
for /R %file in (Filename1.*) DO XCOPY "%file" D:\Data\CopyFilesHere
for /R %file in (Filename2.*) DO XCOPY "%file" D:\Data\CopyFilesHere
for /R %file in (Filename3.*) DO XCOPY "%file" D:\Data\CopyFilesHere
I have since noted there are subfolders I need to search through also.
I want to copy a folder to the same directory and change its name. Let's say, if I have a folder "C:\Users\Desktop\A", how can I copy it, rename it as "B", and still put it at "C:\Users\Desktop"?
Thanks.
xcopy "C:\Users\Desktop\A" "C:\Users\Desktop\B" /e /i
From the command prompt
xcopy source target /E
/E recursivly copies files and directories.
So:
xcopy c:\users\Desktop\A c:\users\Desktop\B /E
The following command copies and moves a file but I also need it to overwrite the file it's replacing.
xcopy /s c:\mmyinbox\test.doc C:\myoutbox
Add /Y to the command line
You can use :
copy /b/v/y
See SS64 on COPY.
Add /y to the command line of xcopy:
Example:
xcopy /y c:\mmyinbox\test.doc C:\myoutbox
you need to simply add /Y
xcopy /s c:\mmyinbox\test.doc C:\myoutbox /Y
and if you're using path with spaces, try this
xcopy /s "c:\mmyinbox\test.doc" "C:\myoutbox" /Y
If the copy command is run from within a batch job you do not need to use the /Y switch: it will overwrite existing files.
For copying one file to another directory overwriting without any prompt i ended up using the simply COPY command:
copy /Y ".\mySourceFile.txt" "..\target\myDestinationFile.txt"
A command that would copy in any case
xcopy "path\source" "path\destination" /s/h/e/k/f/c/y
If destination file is read only use /y/r
xcopy /y/r source.txt dest.txt
Here's what worked for me to copy and overwrite a file from B:\ to Z:\ drive in a batch script.
echo F| XCOPY B:\utils\MyFile.txt Z:\Backup\CopyFile.txt /Y
The "/Y" parameter at the end overwrites the destination file, if it exists.
You can refer Windows command prompt help using following command : xcopy /?