https://sitecam.io/batch-renaming-photos-windows/ - Batch Renaming Photos in Windows
Search This Blog
Monday, November 27, 2023
Friday, July 14, 2023
Zipping files with 7z.exe
cd\
c:
cd rh
REM | BROKEN COMMAND: for /d %%X in (*) do "I:\7-Zip-Command-Line\7za.exe" a "%%X.zip" "%%X\" -mx=5
REM | BROKEN Command: for /d %%X in (*) do "f:\7-Zip-Command-Line\7za.exe" a "%%X.zip" "%%X\" -mx=5
REM | BROKEN Command below this line:
REM | for /d %X in (*) do "c:\Program Files\7-Zip\7z.exe" a "%X.zip" "%X\"
for /d %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a "%%X.zip" "%%X\" -mx=5 –tzip
SET %Today%=%Date:~10,4%_%Date:~4,2%_%Date:~7,2%
ren dr-doc.zip %TODAY%_H-rh-dr-doc_Dr-doc.zip
md "s:\technical documentation\_storage\2023\%TODAY%"
move *.zip "s:\technical documentation\_storage\2023\%TODAY%"
cd\
c:
cd rh-2022
REM | BROKEN Command: for /d %%X in (*) do "f:\7-Zip-Command-Line\7za.exe" a "%%X.zip" "%%X\" -mx=5
REM | UNBROKEN Command below this line:
for /d %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a "%%X.zip" "%%X\" -mx=5 –tzip
ren dr-doc_rh2022.zip %TODAY%_dr-doc_rh2022.zip
move *.zip "s:\technical documentation\_storage\2023\%TODAY%"
pause
md "s:\technical documentation\_storage\2023\%TODAY%\Templates"
cd\
c:
xcopy c:\Users\prhanson\Desktop\Templates\*.* /s "s:\technical documentation\_storage\2023\%TODAY%\Templates"
There was a period in time where my DOS batch file was not functioning correctly so I used the following resource to correct it:
https://stackoverflow.com/questions/34602813/zipping-files-with-7z-exe - Zipping files with 7z.exe
Wednesday, March 15, 2023
Super Super Duper Duper IMPORTANT!! - How to get files out of all subfolders and move them up to the first folder
OH!
MY!
GOSH!
I had no idea I was looking for this information until I found it. How to get files out of all subfolders and move them up to the first folder
This is the relevant information:
From How to Copy Files from Multiple Sub-Folders to a Single Folder?
Open a Command Prompt ('cmd.exe') window. Use the following commands:
cd /d "d:\vacation snaps\2016" for /r %d in (*) do copy "%d" "d:\all snaps"In the above example, the command recursively copies all files in the 'vacation snaps\2016' folder to the 'All Snaps' folder.
Friday, January 20, 2023
Wednesday, January 5, 2022
Of Course
Look at this DOS command: dir *1958*
Simple, right? Nope! In addition to finding "1958.bat" in the folder, it also found this file:
06_Track 6_The Smiths_The Queen Is Dead_40000.mp3
A challenge! Show me 1958 in this file name 06_Track 6_The Smiths_The Queen Is Dead_40000.mp3I am confused, but open to ideas why DOS believes that 1958 is in the following string:06_Track 6_The Smiths_The Queen Is Dead_40000.mp3
I don't see a 1, a 9, a 5, or an 8 in 06_Track 6_The Smiths_The Queen Is Dead_40000.mp3.
Monday, September 13, 2021
Using the FOR Statement
The FOR statement is a command that allows you to "loop" or repeat commands multiple times. It is very similar to the FOR statement provided in several programming languages. The FOR statement is often used in batch files, but it can also be used directly on the command line.
As a reminder, the general form of the FOR loop is:
FOR %variable IN (set) DO command [command-parameters]Where 'variable' is a single letter, '(set)' specifies a set of one or more files, 'command' is the command-prompt command to be executed for each file in the set, and 'command-parameters' are optional parameters to be passed to 'command'.
So let's say you have been given several COM .dll files that you need to register within Windows' Registry. You could put them all in one folder and can then run the following command from within that folder:
C:\DLLs> FOR %i IN (*.dll) DO regsvr32 /s %iWhat this does, for each .dll file it finds in the current directory, is to run the regsvr32 program on it. (The "/s" switch simply tells regsvr32 to do its work silently.) The variable used ("%i") is case sensitive, and it assumes the value of each .dll file in turn. The name of the .dll file is then passed to the regsvr32 program using the same "%i" variable.
A variant of the general FOR loop uses the /L switch and has this general form:
FOR /L %variable IN (start,step,end) DO command [command-parameters]This executes a loop where %variable is first set to 'start' and is incremented by 'step' until it hits the value 'end'. (This usage should be very familiar to programmers.) So let's say you need to display the list of numbers from 1 to 5. You could do it this way:
C:\> FOR /L %i IN (1,1,5) DO @echo %iAnother variant of the FOR loop uses the /D switch and has this general form:
FOR /D %variable IN (set) DO command [command-parameters]With this variant, if 'set' contains wildcards, then the command works on directory names instead of file names. This would be useful, for example, if you wanted to copy a set of files from a directory tree and put all the files in one directory.
For example, I have a directory called \Temp. It contains subdirectories called \Temp\Temp2 and \Temp\Barry. The \Temp\Barry and the \Temp\Temp2 directories contain files I want to copy. If I wanted to copy all of the files (without the directory structure) in the \Temp tree to a directory called \Files, I could do it like this:
C:\Temp> FOR /D %i IN (*) DO Copy %i\*.* \FilesI have left to the end what I think is the most esoteric form of the FOR loop. It seems that using the /F switch will allow you to do almost anything—if you can only figure out how to use it. The general form is:
FOR /F "options" %variable IN (`command`) DO command [command-parameters](Sorry it doesn't all fit on one line.) There are several 'options you can use, and the first 'command' (the one surrounded by the backwards apostrophes) can be any command-prompt command. So here's one example of how to use this:
FOR /F "Usebackq Delims==" %i IN (`dir/b c:\temp\a*.tmp`) DO @echo c:\temp\%i | Findstr /f:/ "a b c"(Sorry it doesn't all fit on one line.) This command performs a DIR/B command on C:\Temp\A*.tmp. For each file it finds, it echoes the file name and pipes it to the Findstr command, which looks for all lines containing an "a", "b", or "c". A pretty odd thing to do, granted, but at least it shows how you can use /F. I suggest you do FOR /? to get a complete list of what all the options are, and then you're basically bound only by your imagination on figuring out how to use it.
You can also use the FOR command within a batch file. The only thing that's different is that you double the %-signs, whereas at the command line you only use one %-sign. For example, if the second example above were to be placed in a batch file, it would look like this:
FOR /L %%i IN (1,1,5) DO @echo %%i