Batch file Filename creates folder and txt file - windows

I am looking to create a batch file that creates a folder, subfolder, and txt file.
I often receive a group of pdf files that I have to review and import into isqft Takeoff.
My usual procedure is to create a folder named after the pdf. Move pdf into folder. Create a txt file with same name. Create a folder named Split. Open PDF in PDFSam and split every page into the Split folder. Extract the bookmarks into the txt file. Use Renamer to rename the split PDFs from teh txt file.
Is there a way to batch this? Or should I focus on a few batch files to complete this? I have searched on here for a solution, but honestly the commands/syntax for batch files really confuse me. I am mainly looking for the folder creation, subfolder creation, txt creation, and if at all possible, the PDFSam splitting.
What is usually received,
/Apartments/plans/Arch.pdf
/Apartments/plans/Civil.pdf
/Apartments/plans/Irrigation.pdf
/Apartments/plans/Landscape.pdf
/Apartments/plans/MEP.pdf
/Apartments/plans/Structural.pdf
How it looks after I mess with everything
/Apartments/plans/Arch/Arch.pdf
/Apartments/plans/Arch/Arch.txt
/Apartments/plans/Arch/Split/File_0001.pdf,File_0002.pdf,etc...

For the basic stuff you can use this:
#echo off
setlocal EnableDelayedExpansion
set "source=C:\Apartments\plans"
FOR %%F IN ("%source%\"*.pdf) DO (
echo %%F
mkdir "!source!\%%~nF"
mkdir "!source!\%%~nF\split"
move "%%F" "!source!\%%~nF"
type nul> "!source!\%%~nF\%%~nF.txt"
)
pause
This creates the folder, textfile, subfolder, and moves the pdfs
For the splitting you should use http://www.sejda.org/, which is the command-line version of PDFSaM.

Related

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

dynamically adjust to the unzipped folder name in a batch file

I'm having trouble setting the correct path to the folder containing my batch file. For example, right now, I have a zipped file called "example.zip". This zip file contains 4 files within it (file1, file2, file3, file4). When a user right-clicks and extracts the 4 files, they are given the option to rename the file path and folder name. By default, the folder name gets saved as "example". In my batch script, I can find and move the files great if they don't change the folder name. But if they change the folder name path to C:\Users\%username%\Downloads\"notexample" then it screws up the batch file.
I'm wondering how to grab the folder path after the user has extracted the the zip file and named it possibly something other than the default name.
My current configuration in my batch script is
for \f "delims=" %%F in ('dir /b /s "cd:~0,2%\Users\%username%\example" 2^>nul') do set filepath=%%F
This is just searching for any folder that matches "example" in the Users\Downloads directory and grabs the file path. You can see the problem if the user renames the folder "notexample". My batch script yells "folder not found"
Thanks
To get a batch file's location is quite simple, use the %~dp0 variable:
echo %~dp0
returns the batch file's folder.
That means you could simply use this:
set "filepath=%~dp0"
This won't require the for loop.

How to use a batch file to delete a line of text in a bunch of text files?

I have a bunch of txt files in my D drive which are placed randomly in different locations. Some files also contain symbols. I want a batch file so that I can delete their specific lines completely at the same time without doing it one by one for each file and please refer to a code which does not create a new text file at some other location with the changes being incorporated i.e. I do not want the input.txt and output.txt thing. I just need the original files to be replaced with the changes as soon as I click the batch file.
e.g
D:\abc\1.txt
D:\xyz\2.txt etc
I want both of their 3rd lines erased completely with a single click and the new file must be saved with the same name in the same location i.e. the new changed text files must replace the old text files with their respective lines removed. Maybe some sort of *.txt thing i.e i should be able to change all the files with the .txt extensions in a drive via a single batch file perhaps in another drive,not placing my batch file into each and every folder separately and then running them. Alternatively a vbs file is also welcomed.
This uses a helper batch file called findrepl.bat from - http://www.dostips.com/forum/viewtopic.php?f=3&t=4697
Place findrepl.bat in the same folder as the batch file below.
It will search for every *.txt file on drive d: and remove line 3.
#echo off
for /r "d:\" %%a in (*.txt) do (
echo processing "%%a"
type "%%a"|findrepl /v /o:3:3 >"%%a.tmp"
move "%%a.tmp" "%%a" >nul
)
pause

Find The Real Location Of Rar File After launching a Batch file

Think I have a compressed file named "Target.rar" and its location is Desktop, inside it I have put a batch script. When I open the rar file (without extracting it) I can see the files inside. If I double click my batch script, winRAR first extract all files into temp folder and will run my batch script from there, so the root directory will be Temp folder, But I need to do something on .rar file location (which is desktop here).
How to get real location of Rar File?
You can search for the rar file if you are confident that you know there won't be any other files with the same name.
dir /b /s C:\Target.rar
Obviously if you know how deep you have to look you can narrow down the search path, and save some time.
If you know it will at least be under C:\Users\%username% then you can use
dir /b /s C:\Users\%username%\Target.rar

Batch script to rename and move files

I have a radio management system which is capable of running batch scripts after shows.
I'm looking for a batch script file that renames any file in the directory like so:
1.mp3 --> [Replay]1.mp3
And then move the file from folder a to folder b.
Any thoughts on how do i go about creating such script in a syntax level?
Here you go
ren *.mp3 [Replay]*.*
There are many ways to do what you request, this script does that by searching all mp3 files in the current folder and move them to folderb specifying a new name.
#ECHO off
FOR %%i IN (*.mp3) DO (
MOVE "%%i" "folderb\[Replay]%%i"
)

Resources