1st off I am not very familiar with advanced programming. I have been following examples and trial and erroring things sometimes with not the right result.
I was up half the night trying to get this to work and was so close but not quite there.
Basically I have a folder structure like this.
JOB NUMBER/Photos
In the photo folder there are 2 sub folders Hi-Res & Low-Res
I need a bat file in the Photos folder that will zip only the JPG in folder Low-Res then name the output zip file as JOB NUMBER - Photos.zip and save it to the photo folder.
On top of this once I had it working I need the zip files to be limited on their size. They must be not larger than 6mb so if they need splitting a simple 01 02 .... Can be prefixed to the zip name.
I briefly saw that you could split the output based on size but didn't get that far!
Any help would be a life saver!!
UPDATE
My code so far.
for %%A in ("%%~dp0\..") do 7z a -tzip "%%~fA-Photos.zip" "Low-Res"
UPDATE
#JonathonReinhart
This gets the Low-res contents zipped & saved back into the Low-res folder which will be fine I just cant get the name on the zip file right. At the moment it saves as Photos-Photos.zip
for %%A in ("Low-res\Photos") do 7z a -tzip "%%~fA-Photos.zip" "Low-Res"
Test this in the photos folder.
#echo off
for %%z in ("%cd%") do (
for %%a in ("%%~dpz%\.") do (
7z a -tzip "%%~nxa-%%~nxz.zip" "Low-Res\*"
)
)
pause
Related
I'm attempting to create a "Image Changer" that can move an image from a folder on my local computer, rename it "wallpaper.jpg," and move it into a profile folder in Firefox, essentially changing it at random.
I need to write a batch file for Windows that will select a random image file from a folder, rename it, and then copy it to another folder. The old image file would then have to be overwritten each time to replace it in the new folder location. I'd still need a copy of that file to keep it in its original location.
FYI, it doesn't need to be a batch file, but that is what I am used to.
Also it would be nice if could loop doing this in the background until I kill the command.
Thanks in advance for your help...
I tried running this
#echo off
setlocal EnableDelayedExpansion
cd \particular\folder
set n=0
for %%f in (*.*) do (
set /A n+=1
set "file[!n!]=%%f"
)
set /A "rand=(n*%random%)/32768+1"
copy "!file[%rand%]!" \different\folder
Which would copy the image to the other folder, but I was struggling to figure out how to rename it.
Really trying to wrap my head around using batch scripts.
Renaming is just the action of moving a file to a file with a different name. That's why there's no rename command in GNU/Linux for example.
In your case \different\folder\wallpaper.jpg should do the trick i think.
Also be sure to test if Firefox supports you to change the wallpaper like that, or if it has to reload for it to change
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
Basically, I'm trying to batch-compress .png images which are residing in various folders. For that, I use pngquant and pngout. Every image should go through these apps this way:
pngquant.exe --force --speed 1 --verbose image.png -o step1.png
pngout.exe step1.png step2.png
I want all images compressed at once. To gather a list of all images in folders, I search with *.png query in root folder. The aim is to just throw all images to batch file and wait for the result.
I looked around a bit and come up with this
for %%i in (*.png) do (
"...\pngquant.exe" --force --speed 1 --verbose "%%~ni.png" -o "%%~ni2.png"
"...\pngout.exe" "%%~ni2.png" "%%~ni3.png" )
So I'm dragging the images onto the .bat file, but only the images from the first folder would go through, the batch file ignores images from the subsequent folders. How can I fix that? Thanks.
for /f "tokens=*" %%i in ('dir *.png /s /b') do (
"pngquant.exe" --force --speed 1 --verbose "%%i" -o "%%~di%%~pi%%~ni2.png"
"pngout.exe" "%%~di%%~pi%%~ni2.png" "%%~di%%~pi%%~ni3.png" )
try this. but note that PNGs will be created in the same folders. don't know however if it was your intent.
Dropping files on the batch file is the same as providing them as arguments on the command line. Your script ignores its arguments and processes just its working directory.
Replace the for argument (*.png) with (%*), which contains the list of all arguments.
Also, instead of %%~ni, which returns just the name of the file, you'll need to say %%~dpni, to include the drive and path, if the files are not in the same folder as the script.
and thank you for any help. I have tried searching for an example on how to accomplish the following, but haven't found anything. Any help would be appreciated as I have no experience in creating a BAT file!
I have a third party program that records audio, and generates an .mp3 file from it. Every 24 hours, it generates a new folder, and begins the process all over again. The problem is, even the slightest bit of sound will generate an .mp3 file. I am left with thousands of .mp3 files that are less than 1 second. I would like to delete all audio files in all of the subdirectories with a length of less than 2 seconds. How can I go about this, and is a BAT file the correct way to accomplish this? The manual way of sorting the files in the many, many directories is a very time consuming process as 20 - 30 days of files will be generated before I am able to go through them.
For a GUI solution: The shareware uncrippled Total Commander can list a full directory tree (control B) and sort by filesize (control F6) and can also display only MP3 files if needed.
This task would just need you to mark the filesizes less than x MBytes in a single pane and then you can delete them all at once.
Another solution is available with a batch file to delete MP3 files of 2.999 seconds or below:
- change [210] to [10] to delete files up to 1.999 seconds.
Download Mediainfo command line version from SourceForge
Change the path to the executable in line 2 below
Launch this batch file in the main folder of the tree of files
If the del commands you see on the screen are right then remove the echo and run it again to delete the files.
#echo off
set "exe=c:\Util\MediaInfo\MediaInfo.exe"
for /r %%a in (*.mp3) do (
"%exe%" -f "%%a" |find "Duration" | findstr /r ": 00:00:0[210]" >nul && echo del "%%a"
)
pause
Im trying to move a picture in every zip folder in current directory. I searched online for some guidance on how to do it using batch (.bat) and the only solution I figured out is to make a macro of it but it takes too long for it to complete.
Edit:
I have 50 zip folders which I want to add a picture inside each one in a faster way other than draging the picture each time inside each of the 50 zip folders.
I would appreciate any other ideas and help you could offer.
Test this on some sample zip files in a test folder. It assumes 7-zip is in the folder shown.
It's not so much faster as it is easier, without manually manipulating the files.
The actual zipping speed will be pretty much the same.
#echo off
for /f "delims=" %%a in ('dir *.zip /b /a-d') do (
"C:\Program Files\7-Zip\7z.exe" a "%%a" "my-picture.jpg"
)
pause
Adds (or updates) README.txt in the zipfiles foo.zip and bar.zip from README.txt in the current directory:
$ for f in foo.zip bar.zip ; do zip -u $f README.txt ; done
You can package files into a zip file using the Winzip utility. It must be installed on your computer. Follow these steps:
Select the files you need and click on any of the selected ones.
Select Add to Zip
In the Add window, in the Add to Archive field, specify the path and name of the archive to be created.
The ZIP file is saved at the path you specified.