I want to copy all files within subfolders to the parent folder. But want to create a new folder in it by the name "copied" in whichever folder i have copied my batch file. I tried this command.
FOR /R %%# IN (*.*) DO XCOPY "%%#"
It does the job but it keeps asking to rewrite files. Also wasn't sure how to create the folder name in which i have copied my batch file into.
Related
I have a root directory with over 25,000 files in it. These files are in loads of different subdirectories.
I also have a text file with 4300 lines in it, each line is an absolute path to one of the files in the directory. Like below,
c:\dir1\hat1.gif
c:\dir1\hat2.gif
c:\dir1\dir2\hat1.gif
c:\dir1\dir2\hat2.gif
c:\dir1\dir3\cat.zip
c:\dir1\dir3\banana.exe
I also have another root directory witch is a copy of the original root directory structure but all the directories are empty.
I would like to copy all the files listed in the text file to the directory which is empty and place all the copied files inn the respected subdirectories.
if I use the following batchfile I keep getting file overwrite prompts because it is not copying the files to the correct directories.
#echo off
set dst_folder=c:\DSTN2
for /f "tokens=*" %%i in (USEDFILES.txt) DO (
xcopy /S/E "%%i" "%dst_folder%"
)
How do I modify this so the files are copied to the correct directory?
Since you are copying specific files from a list, you need to make sure the directory structure exists in the destination if you want it in a similar folder structure. So using the power of the FOR command modifiers you can get the file path only from the file name in the file list. You will use that modifier to create the destination directory and also use it as the destination for the XCOPY command.
I have taken the liberty of providing best practices for all the code you are using.
#echo off
set "dst_folder=c:\DSTN2"
for /f "usebackq delims=" %%G in ("USEDFILES.txt") DO (
mkdir "%dst_folder%%%~pG" 2>NUL
xcopy "%%~G" "%dst_folder%%%~pG"
)
I have a batch script which moves all the files from one folder to another and then renames them all to .jpg, however my .bat file itself gets renamed in the process because it sits in the destination folder. I need to exclude it from getting renamed.
Also, does the ren command exclude items in subfolders by default? I only want items in the destination folder renamed, not items in its subfolders.
#echo off
xcopy "C:\Folder1" "C:\Folder2"
cd "C:\Folder2" && ren *.* *.jpg
pause
So I have a problem: I usually need to run a folder through an exe, but now I need to run all the folders in a main directory. They don't have any folder depth so one subfolder has no other subfolders. Essentially I drag and drop a folder onto my exe and I get a file from it, I need a batch script that runs all the folders in my directory individually through the exe, as when I run multiple folders through the exe, I still get a single file.
I found this code and this works for all files with the suffix .emb
#echo off
for /r %%i in (*.emb) do "embpack_v2.exe" "%%i" ALL
but I need it to run folders, not files ending in .emb
try with
for /r /d %%i in (*) do "embpack_v2.exe" "%%i" ALL
I need to copy any pdf files with the word "approved" in the file name from here:
C:\Projects\Project_1\
C:\Projects\Project_2\
To here:
C:\Attachments\Project_1\Documents\
C:\Attachments\Project_2\Documents\
The batch file needs to create the project folder as well as 2 subfolders, "Documents" and "Images" and put the corresponding pdf files in the "Documents" folder.
I created a simple batch file using xcopy but I cannot figure out a way to put the pdfs into a subfolder.
xcopy "C:\Projects\Project_1*approved*" "C:\Attachments\" /s /d /y
I was wondering if there is a quick and dirty command that can copy all files in a directory and it's subdirectory to another folder. The destination folder will have no subdirectories just all the source files.
Also as an added bit of fun, in case there is a file name conflict, not to overwrite but to rename the destination file with something unique, maybe append _1 to the filename?
This will copy the files and prompt if there is a filename conflict.
The third party tool XXcopy has the ability to flatten a directory tree and handle filename conflicts.
#echo off
for /r "d:\folder" %%a in (*) do copy "%%a" "E:\target folder"
To copy for instance all files from the current folder and its sub directories to the parent folder of the current folder you can use:
for /r . %a in (*) do copy %a ..