Batch file to create folders and subfolders and copy files into them - windows

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

Related

Copying 1 file into multiple subfolders

I am a novice. I am trying to copy 1 file into multiple subfolders within windows file explorer. I have successfully copied 1 file into multiple folders within a specified drive using the template below using the CMD prompt.
for /D %a in ("path-to-folder*.*") do xcopy /y /d "Path-to-file\file.FileExt" "%a"
This successfully copies one file to all folders within a specified folder.
Unfortunately I need to copy 1 file into multiple subfolders within a file. I will try to explain as best I can below:
I need an Excel file to copy to all Facility Subfolders within a Facility Folder under Folder1.
File.xls --> Folder 1 --> Facility Folder --> Facility Subfolder
Does that make sense? I need to do this frequently and copy and pasting the excel file to all facility subfolders is time consuming.
Thank you for any assistance!
D

Batch OCR files in subfolders and save new files with new name

I have the following code, which OCR's all PDF files in a specific folder (d:\extracttmp2), but it does not rename the files as I would like, or put the new files in the right place.
Currently, all files are within subfolders of 'extracttmp2'.
The OCR runs correctly, but I would like the OCR'ed files to be renamed to: <parent folder path>-<filename>_ocred.pdf. Naming them in such a manner will produce no file overwrites.
Currently, the code OCR's the files, but it saves the new files to the folder above the folder they are located in. It also saves the filenames as "JAN_ocred.pdf", for example, for a file named "JAN.pdf". The result of saving up one folder leads to some file overwrites, which is unwanted.
Also, it doesn't matter if the OCR'ed files remain in the folder where the un-OCR'ed files are located, or if they're saved up one folder. The desired renaming will eliminate any overwrites.
The software I'm using is PDF24. https://creator.pdf24.org/manual/10/#command-line. However, I think that my problem is not with the OCR software, but my syntax in the batch script.
Can anyone tell me what I am doing wrong?
For /R d:\extracttmp2\ %%G in (*.pdf) do "C:\Program Files\PDF24\pdf24-Ocr.exe" -outputFile "%%~nG_ocred.pdf" -language eng -dpi 300 -skipFilesWithText "%%G"
Is this what you mean? i.e. files will be saved in the same location as before, but each name will be prefixed with their parent directories' name, followed by a hyphen/dash.
#For /R "D:\extracttmp2" %%G In (*.pdf) Do #For %%H In ("%%~dpG.") Do #"%ProgramFiles%\PDF24\pdf24-Ocr.exe" -outputFile "%%~nxH-%%~nG_ocred%%~xG" -language eng -dpi 300 -skipFilesWithText "%%G"
Just a quick clarification: D:\extracttmp2\directory1\JAN.pdf would be saved in the working directory with the name directory1-JAN_ocred.pdf, and D:\extracttmp2\directory2\subdirectory3\SOMENAME.pdf, as subdirectory3-SOMENAME_ocred.pdf
If you want to save the files somewhere else, either change the working directory, or prepend it to %%~nxH-%%~nG_ocred%%~xG

how to copy all files in subfolders to the parent folder

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.

Batch script to copy folder structure with files skip specific sub-folders

I am trying to copy a folder structure with all data but need to skip folders who have named as 'others'. I created .bat file and trying to move source to destination. I used xcopy /e and exist to check folder but I can't make it. How can I do it?
Use robocopy /E /XD <exclude_file>. See robocopy /? for more options.
create a exclude.txt list into which you can specify which folders or sub folders you want to skip.
use
xcopy "source" "destination" /EXCLUDE:exclude.txt

How to copy all *.txt files from subfolder to batch file folder using this batch-file?

I have main folder that contains "batch.bat" file and 1 subfolder named "Carrol".
This "Carrol" subfolder contains many files with different types.
I need to copy all txt files from "Carrol" subfolder to main folder with this "batch.bat" using commands of this "batch.bat" file
How can I do that?
Inside batch.bat
for %%i in (Carrol\*txt) do move Carrol\%%i %~dp0

Resources