I am trying to exclude copying the files from the path :
AlreadyCopied.txt.
AlreadyCopied.txt looks like this:
file 'E:\teste-batch-file\original\CG Animation Of Outerspace - Copy - Copy - Copy (1) - Copy.mp4'
file 'E:\teste-batch-file\original\CG Animation Of Outerspace - Copy - Copy - Copy (2) - Copy.mp4'
file 'E:\teste-batch-file\original\CG Animation Of Outerspace - Copy - Copy - Copy (3) - Copy.mp4'
file 'E:\teste-batch-file\original\CG Animation Of Outerspace - Copy - Copy - Copy (4) - Copy.mp4'
I used xcopy
xcopy "%Source%\*.mp4" "%Target%" /EXCLUDE:AlreadyCopied.txt
I also tried with RoboCopy:
RoboCopy "%Source%\*.mp4" "%Target%" /XF "AlreadyCopied.txt" /Copy
Both with no luck.
Thank you for help.
Related
I'm learning about CMD for loops. I created a directory tree rooting in the folder C:\Users\Ahmed\Desktop\Playing_Field:
├───New folder - Copy
├───New folder - Copy (10)
├───New folder - Copy (11)
├───New folder - Copy (12)
├───New folder - Copy (13)
├───New folder - Copy (14)
├───New folder - Copy (15)
├───New folder - Copy (16)
├───New folder - Copy (17)
├───New folder - Copy (18)
├───New folder - Copy (19)
├───New folder - Copy (2)
├───New folder - Copy (20)
├───New folder - Copy (21)
├───New folder - Copy (22)
├───New folder - Copy (23)
├───New folder - Copy (24)
├───New folder - Copy (25)
├───New folder - Copy (26)
├───New folder - Copy (27)
├───New folder - Copy (28)
├───New folder - Copy (29)
├───New folder - Copy (3)
├───New folder - Copy (30)
├───New folder - Copy (31)
├───New folder - Copy (32)
├───New folder - Copy (33)
├───New folder - Copy (34)
├───New folder - Copy (35)
├───New folder - Copy (36)
├───New folder - Copy (4)
├───New folder - Copy (5)
├───New folder - Copy (6)
├───New folder - Copy (7)
├───New folder - Copy (8)
└───New folder - Copy (9)
Then I tried to filter through them using this command:
for /d %n in (C:\Users\Ahmed\Desktop\Playing_Field\*3*) do #echo "%n"
The output was:
"C:\Users\Ahmed\Desktop\Playing_Field\New folder - Copy (10)"
"C:\Users\Ahmed\Desktop\Playing_Field\New folder - Copy (20)"
"C:\Users\Ahmed\Desktop\Playing_Field\New folder - Copy (16)"
"C:\Users\Ahmed\Desktop\Playing_Field\New folder - Copy (13)"
"C:\Users\Ahmed\Desktop\Playing_Field\New folder - Copy (23)"
"C:\Users\Ahmed\Desktop\Playing_Field\New folder - Copy (3)"
"C:\Users\Ahmed\Desktop\Playing_Field\New folder - Copy (30)"
"C:\Users\Ahmed\Desktop\Playing_Field\New folder - Copy (31)"
"C:\Users\Ahmed\Desktop\Playing_Field\New folder - Copy (32)"
"C:\Users\Ahmed\Desktop\Playing_Field\New folder - Copy (33)"
"C:\Users\Ahmed\Desktop\Playing_Field\New folder - Copy (34)"
"C:\Users\Ahmed\Desktop\Playing_Field\New folder - Copy (35)"
"C:\Users\Ahmed\Desktop\Playing_Field\New folder - Copy (36)"
"C:\Users\Ahmed\Desktop\Playing_Field\New folder - Copy (2)"
Why are there some folders in the output that do not contain 3 in their names, such as New folder - Copy (2)?
Modern Windows systems still support so-called short file names and even may have them enabled by default, besides the usual long files names. These short file names, also called 8.3 names (because of up to 8 characters for the base name and up to 3 characters for the extension), originate from MS-DOS and pre-Windows 95 systems, and are automatically generated in the background1.
To display such short file names, use the dir command, together with its /X option:
>>> dir /X /-C /A:D-H-S "%SystemDrive%\Progr*"
Volume in drive C has no label.
Volume Serial Number is 0000-0000
2022/07/10 19:00 <DIR> PROGRA~1 Program Files
2022/07/10 19:00 <DIR> PROGRA~2 Program Files (x86)
0 File(s) 0 bytes
2 Dir(s) 412316860416 bytes free
Now wildcards (like * and ?) match against both the long and the short file names:
>>> dir /X /-C /A:D-H-S "%SystemDrive%\Pro*1"
Volume in drive C has no label.
Volume Serial Number is 0000-0000
2022/07/10 19:00 <DIR> PROGRA~1 Program Files
0 File(s) 0 bytes
1 Dir(s) 412316860416 bytes free
To always match against the long file names, use find or findstr to post-filter the returned items by dir /B:
>>> dir /B /A:D-H-S "%SystemDrive%\Progr*" | find /I "Program"
Program Files
>>> dir /B /A:D-H-S "%SystemDrive%\Progr*" | findstr /I /B "Program"
Program Files
Or, applied to your code, using for /F to capture the result:
>>> for /F "eol=| delims=" %I in ('dir /B /A:D-H-S /O:N "%UserProfile%\Desktop\Playing_Field\*3*" ^| find /I "3"') do #echo "%I"
"C:\Users\Ahmed\Desktop\Playing_Field\New folder - Copy (13)"
"C:\Users\Ahmed\Desktop\Playing_Field\New folder - Copy (23)"
"C:\Users\Ahmed\Desktop\Playing_Field\New folder - Copy (3)"
"C:\Users\Ahmed\Desktop\Playing_Field\New folder - Copy (30)"
"C:\Users\Ahmed\Desktop\Playing_Field\New folder - Copy (31)"
...
>>> for /F "eol=| delims=" %I in ('dir /B /A:D-H-S /O:N "%UserProfile%\Desktop\Playing_Field\*3*" ^| findstr /I "3"') do #echo "%I"
"C:\Users\Ahmed\Desktop\Playing_Field\New folder - Copy (13)"
"C:\Users\Ahmed\Desktop\Playing_Field\New folder - Copy (23)"
"C:\Users\Ahmed\Desktop\Playing_Field\New folder - Copy (3)"
"C:\Users\Ahmed\Desktop\Playing_Field\New folder - Copy (30)"
"C:\Users\Ahmed\Desktop\Playing_Field\New folder - Copy (31)"
...
1) Note that disabling the short file names will not remove already generated such names.
I am trying to copy files from folder1 to folder2 but exclude few files. lets say
Source dir: D:\test1
Dest dir: D:\test2
Source dir has files: hello1.txt, hello2.txt, hello3.pdf.....(and so on with different extension)
My batch cmd: Xcopy /Y /exclude:D:\test1\Excludefiles.txt D:\test1 D:\test2
I have added list of files in Excludefiles.txt that I dont want to copy.
The issue is everything works fine except Excludefiles.txt gets copied in dest folder too which I dont want. How can I exclude Excludefiles.txt getting copied?
I'm trying to copy a dll file to another PC of the same network by using the batch file. But when I run the batch file, it says File not found.
Here's the code I'm using for the batch file.
#echo off
FOR /F "delims=" %%i IN ("%CD%\targets.txt") DO (
xcopy /Y "%CD%\RevitDMS.dll" "%%i"
)
pause
Here is the text is written in the targets.txt file:
"\192.168.6.205\%USERPROFILE%\Desktop\"
here is the folder location where the batch file is located, as we can clearly see the RevitDMS.dll has located already in the same directory.
Would appreciate if anyone helps me figure out the solution. Thanks in Advance.
On a server i have a main folder that contain many subfolder and file with some extension.
I would like to compress only file with extension *.bak and each file zip created in right subfolder path.
Example:
- Folder
-- Subfolder1
--- File.zip
--- File.bak
-- Subfolder2
--- File2.zip
--- File2.bak
Now I use this script to compress:
cd /Folder/Subfolder1
set extension=.bak
for %%a in (*%extension%) do 7za.exe a "%%~na.zip" "%%a"
cd /Backup/Subfolder2
set extension=.bak
for %%a in (*%extension%) do 7za.exe a "%%~na.zip" "%%a"
This script is right, but Ihave to remember to create new lines everytime that I have a new subfolder.
I there a solution that check every subfolder for *.bak files and compress it in each subfolder?
Thankyou very much and sorry for bad english.
Addendum:
I tried this command:
set extension=.bak
for **/R** %%a in (*%extension%) do 7za.exe a "%%~na.zip" "%%a"
this search correctly every *.bak in every subfolder, create a single zip for every bak that find BUT it create the n. zip file all in main folder...
This is my copy command :
set POLL="C:\Documents and Settings\"
copy Register.class+Ca.class+pack %POLL% /-Y
pack is a folder here.
The result of the above copy coman is that only Register.class gets copied to the destination folder. What's my mistake?
Naming multiple source files for a copy command copies the files into one single file.
copy fileone + filetwo filethree
would result in filethree containing the content of fileone AND filetwo. You cannot copy multiple files to a different location with copy.
However it is fairly easy to do so using either a loop or xcopy-command:
set POLL="C:\Documents and Settings\"
FOR %%F IN (Register.class Ca.class) DO copy %%F %POLL% /-Y
xcopy pack %POLL% /-Y