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"
Related
I was researching but there's no answer about a command in Robocopy to do the following:
I want to copy in a single folder all *.log files (just the file not the directory that contain the file) from multiple folders in a single path.
The source tree is the folowing:
c:\QA\1\1.log
c:\QA\2\2.log
c:\QA\3\3.log
c:\QA\4\4.log
... and so on ...
e.g.
Source: c:\QA
Destination: c:\QA\LOG
File: *.log
I made this batch file but it also copies the folders which contain the files.
#echo
ROBOCOPY C:\QA\ C:\QA\LOG\ *.log /s
pause
OK, this is the solution, thanks to Chris Nathaniel
batch file:
#echo
for /R C:\QA\ %%f in (*.log) do copy %%f C:\QA\LOG\
pause
cmd.exe:
for /R C:\QA\ %f in (*.log) do copy %f C:\QA\LOG\
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 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
I wish to copy a file with extension .dyn which is located in each subfolder of main folder(T15_finished). I wish to copy it into respective subfolder at other location(T15). I have created that location using xcopy command. Here, .dyn file is being copied successfully in respective subfolder in T15 folder(see below code). Now, I have a file which has extension as .dynain which is located in the same subfolder as .dyn. And .dynain file is also getting copied which i don't want.
Please see following code which i have created. Can anyone tell me whats wrong ?
#echo off
xcopy D:\Master\SPRINGBACK\CPW\T15_finished D:\Master\SPRINGBACK\FRESH_SPRINGBACK\CPW\T15 /t
xcopy /e D:\Master\SPRINGBACK\CPW\T15_finished\*.dyn D:\Master\SPRINGBACK\FRESH_SPRINGBACK\CPW\T15
pause
Short file names. If you do a dir /x in the folder containing the .dynain file, you will see the 8.3 filename generated for the file, and it will have .dyn extension.
If you know the extensions of the conflicting files, you can use robocopy with /xf switch to indicate the files (*.dynain) to exclude, or you can generate a exclude file to use with xcopy /exclude:file (see xcopy /? for a explanation)
Or, you can generate the list of files to exclude
(for /f "tokens=" %%a in (
'dir /s /b "D:\Master\SPRINGBACK\CPW\T15_finished\*.dyn" ^| findstr /v /i /e /l ".dyn"'
) do #echo(%%~nxa)>excludedFiles.txt
xcopy /exclude:excludedFiles.txt /e D:\Master\SPRINGBACK\CPW\T15_finished\*.dyn D:\Master\SPRINGBACK\FRESH_SPRINGBACK\CPW\T15
Or (as posted by foxidrive), copy all and then delete the non needed files.
The short filename is being matched as well as the long filename. That is the reason.
A solution is to use another command to delete the files:
del /s "D:\Master\SPRINGBACK\FRESH_SPRINGBACK\CPW\T15\*.dynain"