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

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

Related

How to batch copy a list of folders and its file contents from a text file into a new folder in windows

I have a folder with approximately 7000 subfolders. I am interested in copying 1500 of those subfolders and their file contents into a new folder.
The closest I have got is copying the subfolders file contents into a new Target folder. However, the file contents are not copied over within their resepective subfolder making the batch copy useless to me.
Here is what I have tried.
CD E:\Source_Folder
FOR /F "delims=" %%N in (List.txt) do COPY "%%N" "Target_Folder"
I have tried XCOPY, ROBOCOPY, as well and all give me the same output of individual files in my target folder. I am looking for the subfolders with their contents to be copied into my new target folder.
Any help would be much appreciated. Thanks!
Just a try: rsync in linux does have the option to take the file-list to be synced from a file. Maybe robocopy (which is the windows-pendant) has the same capability, then you need one robocopy x y z only.
-edit: robocopy can'r read from a file, but if you search for 'robocopy reading from list' you get a lot of short scripts.

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.

Batch file Filename creates folder and txt file

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.

Script to list the files of a folder and export it to a text document

I was just wondering if anyone knew of a way that you could get all the folders, files and sub-folders of a location (such as C:\Users\Username) and export it to a text document on a network share (such as \server\share\document.txt).
Thank you for your help!
From the command line (or use a batch file if you're going to need this a lot):
dir c:\users\username > \\server\share\document.txt
that should do the trick
The following command will show all files in the specified directory and all sub-directories and redirect the output to a file on a server share.
dir /s c:\Users\Username > \\server\share\document.txt
Add the /b option if you want to see the files with the full path included in the file name.
dir /s /b c:\Users\Username > \\server\share\document.txt

Resources