This has been tested in Windows 7 Professional. No error checking of any kind is performed. It renames the files in the current directory, so the script should be somewhere on your path.
@echo off
set /p start=Please enter the starting control number:
setlocal enableDelayedExpansion
for /r %%g in (*.pdf) do (call :RenameIt %%g)
goto :eof
goto :exit
:RenameIt
echo Renaming "%~nx1" to !start!%~x1
ren "%~nx1" !start!%~x1
set /a start+=1
goto :eof
:exit
exit /b
Hope that helps!
I've been merging (concatenating) videos lately, and I found this answer very useful. To start with, install ffmpeg and make sure it's on your path.
You have to make a list of files for each dir that consists of a text file in this format:
file `file1.mp4`
file `file2.mp4`
file `file3.mp4`
Then you just run ffmpeg with this syntax:
ffmpeg -f concat -i filelist.txt -c copy merged.mp4
I was constructing these by hand for a few files, but for 158 folders you'll want some automation. The approach I'd take is probably using the FOR
command in the Windows command prompt. You can generate the file lists using something like:
for /r %f in (*.mp4) do echo file '%~nxf' >>%~dpf\concat.txt
This recursively (/r
) scans the MP4 files in the current folder and all subfolders, and echoes (prints) the name and extension (that's the nx
bit) to a separate file in each subfolder (the dp
bit gets the drive letter and path). The >>
bit makes it append the filename to the list, so if you run this twice you'll get a duplicated list. So delete any concat.txt
files before running the command.
Then you want to run ffmpeg on each of those. You'll need something like:
for /d %f in (*) do cd %~ff & ffmpeg -f concat -i concat.txt -c copy ..\merged\%~nf.mp4
For each directory (/d
), change into it (cd
), and (&
) run ffmpeg, generating a result file that goes in the "merged" folder of the top-level folder, and is named after the folder name.
Not tested, so use at your own risk. (Although it won't delete or overwrite anything without asking.)
Best Answer
On Linux, assuming you want 3-digit numbers, and that the number is always between 2 underscores:
The
rename
program may already be installed. It is a simple program that takes a Perl expression and uses it to rename the given files, orfoo*
in this case. The Perl expression here captures the number between parentheses and usessprintf
to convert it to a 3-digit number. Use%04d
, above, for 4-digit numbers.This can also work on Windows 10 using WSL.