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
Related
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 copy lot of *.txt file from multiple folders to one.
I try use for exp.:
xcopy D:\Dokumenty\*.txt D:\final /sy
But this make 1:1 copy of folder. I need copy only files to a new folder.
Thanks for help.
You can also use wildcard (?*) in ROBOCOPY
usage: ROBOCOPY source destination [file [file]...] [options]
Transposing your example should look like this:
ROBOCOPY "D:\Dokumenty\" "D:\final" *.txt /S
for /r "D:\Dokumenty\" %%# in (*.txt) do copy /y "%%~f#" "D:\final"
i have a batch script that i want it to copy everything inside a specific folder to another but it only copy files it doesn't copy the sub folders.
thanks in advance
Here is how im copying the inside of the folder:
xcopy /s %FILETOZIP% %TEMPDIR%
Using XCOPY, the parameters should be at the end:
XCOPY source [destination] [options]
If any folders are empty and you want to include them, you will need the /E parameter instead.
Try the following to capture the entire directory structure:
xcopy %FILETOZIP% %TEMPDIR% /s /e
Is there a way to copy directories recursively inside a .bat file? Is an example of this available?
Look into xcopy, which will recursively copy files and subdirectories.
There are examples, 2/3 down the page. Of particular use is:
To copy all the files and subdirectories (including any empty subdirectories) from drive A to drive B, type:
xcopy a: b: /s /e
After reading the accepted answer's comments, I tried the robocopy command, which worked for me (using the standard command prompt from Windows 7 64 bits SP 1):
robocopy source_dir dest_dir /s /e
You may write a recursive algorithm in Batch that gives you exact control of what you do in every nested subdirectory:
#echo off
call :treeProcess
goto :eof
:treeProcess
rem Do whatever you want here over the files of this subdir, for example:
copy *.* C:\dest\dir
for /D %%d in (*) do (
cd %%d
call :treeProcess
cd ..
)
exit /b
Windows Batch File Looping Through Directories to Process Files?
I wanted to replicate Unix/Linux's cp -r as closely as possible. I came up with the following:
xcopy /e /k /h /i srcdir destdir
Flag explanation:
/e Copies directories and subdirectories, including empty ones.
/k Copies attributes. Normal Xcopy will reset read-only attributes.
/h Copies hidden and system files also.
/i If destination does not exist and copying more than one file, assume destination is a directory.
I made the following into a batch file (cpr.bat) so that I didn't have to remember the flags:
xcopy /e /k /h /i %*
Usage: cpr srcdir destdir
You might also want to use the following flags, but I didn't:
/q Quiet. Do not display file names while copying.
/b Copies the Symbolic Link itself versus the target of the link. (requires UAC admin)
/o Copies directory and file ACLs. (requires UAC admin)
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.