Hi cats,
thanks to ndjamena I use this script to transcode any mxf files, but now I would like use the base script to rename a list of .mxf files
I have a list of mxf that are numerated as this example:
C0001.MXF
C0002.MXF
C0003.MXF
C0004.MXF
etc...
the date of C0001.MXF (24.08.2015 13:57:53) is lower of the date of C0002.MXF (13:58:04)
the date of C0002.MXF (24.08.2015 13:58:04) is lower of the date of C0003.MXF (13:58:14)
etc...
My target is rename all .mxf starting from a number that I input to the batch when he ask me it:
for example I need to rename all .mxf starting from C0501
the batch have to rename all .mxf so that
C0001.MXF -----> renamed to C0501.MXF
C0002.MXF -----> renamed to C0502.MXF
C0003.MXF -----> renamed to C0503.MXF
etc...
OR another example: in the num inputted is 655 the batch have to:
C0001.MXF -----> renamed to C0655.MXF
C0002.MXF -----> renamed to C0656.MXF
C0003.MXF -----> renamed to C0657.MXF
etc...
I have this batch but it don't work well:
For example I apply the batch to the first 8 mxf file in my folder (I have drag and drop the first 8 files into the batch icon, C0001.MXF C0002.MXF C0003.MXF C0004.MXF C0005.MXF C0006.MXF C0007.MXF C0008.MXF) starting numeration (%num%) from 501, but it produces this bad result:Code:@rem unless otherwise specified for debugging reasons turn echo off @if "%EMode%"=="" Set EMode=ON @ECHO %EMode% @ECHO off cls SetLocal DisableDelayedExpansion Set "EXTLIST=*.MXF" Set "DoPop=0" Set "ARGLVL=0" Set "FileName-DQ=" Set VD_LOC="v:\automazioneclip\VirtualDub\vdub.exe" set "DestFolder=." Set "WorkFolder=%DestFolder%" rem process the arguments one by one set /p "num= INSERT START NUMERATION: " :ARGS color rem if there are no further arguments then exit the batch. if [%1]==[] ( if "%ARGLVL%"=="0" ( CALL :GetTargetName EndLocal pause ) goto :eof ) rem wildcard processing Set "FileName=%~1" if "%FileName%"=="" ( SHIFT goto :ARGS ) rem if the argument doesn't exist in the file system in any form skip it. if NOT EXIST %1 ( SHIFT goto :ARGS ) if NOT [%1]==[] if NOT "%FileName:^*=%%FileName:^?=%"=="%FileName%%FileName%" ( for %%w in (%1) DO ( Set /a ARGLVL+=1 CALL :ARGS "%%~fw" Set /a ARGLVL-=1 ) SHIFT goto :ARGS ) Set "FileName=" rem Set search/recursion variables Set "Pattern=%EXTLIST%" Set "STARTLVL=0" Set "FOUNDLVL=1024" rem if the argument is the current directory then process everything in it. if "%~f1"=="%CD%" ( rem echo Processing Directory "%CD%" CALL :START %1 SHIFT goto :ARGS ) rem Test if the argument is a directory, if it is move to it then process everything in it, if not then move to the file's parent directory and process the file. Then return to starting directory. Type NUL pushd "%~f1" 2> nul if NOT "%errorlevel%"=="0" ( if NOT "%CD%\"=="%~dp1" ( pushd "%~dp1" Set "DoPop=1" ) Set Pattern="%~nx1" ) else ( rem echo Processing Directory "%~f1" Set "DoPop=1" ) CALL :START %1 if "%DoPop%"=="1" ( popd Set "DoPop=0" ) SHIFT goto :ARGS :START <CURRENT_ARG> color rem Count is superseded by FOUNDLVL but may still be useful for renaming purposes Set "Count=0" rem Process all files in the current directory fitting the arguments search pattern. for /F "delims=" %%y in ('dir %Pattern% /b /o:-d /t:w') do ( if /I NOT "%%~y"=="File Not Found" CALL :Process_File "%%~fy" ) rem if it didn't find anything search all directories instead goto :eof if "%Count%"=="0" if %STARTLVL% LSS %FOUNDLVL% ( for /d %%b in (*) do ( pushd "%%~fb" rem echo Processing Directory "%%~fb" Set /a STARTLVL+=1 CALL :START "%%~fb" Set /a STARTLVL-=1 popd ) ) goto :eof :Process_File <FILENAME> color rem *** check if file is MXF Set "TokenS=0" Set "isMXF=0" IF "%~x1"==".MXF" Set "TokenS=1" IF "%~x1"==".mxf" Set "TokenS=1" If "%TokenS%"=="1" Set "isMXF=1" if "%isMXF%"=="1" (CALL :MXFrenaming "%WorkFolder%\%~n1.vcf" "%WorkFolder%\%~n1.avs" "%WorkFolder%\%~n1.avi" "%~f1") echo DONE echo. echo --------------------------------------------- echo. EndLocal goto :eof :MXFrenaming <VCF_FILENAME> <AVS_FILENAME> <FILENAME> <ORG_FILENAME> echo *** MXF renaming routine *** echo processing "%~dp1%~n1.MXF" for /L %%a in (%num%,1,999) do ( if not exist "%~dp1C0%%a.mxf" (ren "%~dp1%~n1.MXF" "C0%%a.MXF" if exist "%~dp1C0%%a.mxf" set "FilenameForCameraOnline=%~dp1C0%%a.mxf">"%~n1"_renamed_in_"C0%%a_MXF".log) ) goto :eof :GetTargetName color Set "FileName=" Set /p FileName=InputFileName rem Add or remove double-quotes if necessary if NOT DEFINED FileName ( Set "FileName-DQ=" goto :DQSkip ) Set "FileName-DQ=%FileName:"=%" if NOT DEFINED FileName-DQ ( Set "FileName=" Set "FileName-DQ=" goto :DQSkip ) if EXIST "%FileName-DQ%" ( if "%FileName-DQ%"=="%FileName-DQ: =%" ( Set "FileName=%FileName-DQ%" ) else ( Set FileName="%FileName-DQ%" ) ) :DQSkip color if /I "%FileName-DQ%"=="" Set FileName="%CD%" if /I "%FileName-DQ%"=="CD" Set FileName="%CD%" if /I "%FileName-DQ%"=="EXIT" goto :eof if /I "%FileName-DQ%"=="NOEXIT" goto :GetTargetName if DEFINED FileName ( Set /a ARGLVL+=1 CALL :ARGS %FileName% Set /a ARGLVL-=1 ) goto :GetTargetName
the problem is that the renaming is not in sequence with the date of the older file present in the folder.
I would like to modify the batch so that:
C0001.MXF -----> have to renamed in C0501.MXF (and not C0504.MXF, because C0001.MXF is the older file present in the folder)
C0002.MXF -----> have to renamed in C0502.MXF (and not C0505.MXF, because C0002.MXF is the older file present in the folder, after renaming C0001.MXF)
C0003.MXF -----> have to renamed in C0503.MXF (and not C0506.MXF, because C0003.MXF is the older file present in the folder, after renaming C0001.MXF and C0002.MXF)
it it possible this?
THANKS
Try StreamFab Downloader and download from Netflix, Amazon, Youtube! Or Try DVDFab and copy Blu-rays! or rip iTunes movies!
+ Reply to Thread
Results 1 to 18 of 18
Thread
-
Last edited by marcorocchini; 5th Dec 2015 at 05:49.
-
*sigh*
So basically, you highlighted 1 to 8 then you clicked on 6 and dragged IT onto the batch. And of course the batch did 6 first, no?
Try clicking on 1 instead and dragging IT onto the batch. -
yes I have highlighted 1 to 8 and dragged the selection onto the batch
using 501 as starting sequence
but results is wrong:
I don't well understand what means "Try clicking on 1 instead and dragging IT onto the batch": if I drag&drop the C0001.MXF the batch change only C0001.MXF in C0501.MXF
is there another way? -
-
The file names are sent starting with the particular file you drag. So if you highlight 13 to 21, but drag 17 to the batch file the order the batch file receives the names is 17, 18, 19, 20, 21, 13, 14, 15, 16.
-
Interestingly enough, Windows 10 doesn't do that. However, if I write a batch to rename the contents of an entire directory it starts from the first file, renames every single file in the directory and then processes the first file again, leaving me with a numbering that starts at 2 and sorts the first file last. Add to that, if I have a file with a path name that contains a comma and no spaces and try to drag THAT onto a batch, the path will be split into two arguments at the comma and the batch won't be able to process the file at all.
-
as a side note: I use Flex Renamer (http://hp.vector.co.jp/authors/VA014830/english/FlexRena/) for such tasks,...
users currently on my ignore list: deadrats, Stears555 -
-
Even cats aren't so stubborn as to ignore other, better options: Use one of the many good batch file renamers (Flex Renamer, as mentioned above, A Better File Renamer, Bulk Rename Utility, 1-for-A File Renamer,...). It's like you're going out of your way to make it more difficult. Same with the other thread (virtual drive issue, which I gave an elegant solution for - SUBST - and you ignored).
"You can lead a cat to milk, but you can't make him drink."
Scott -
mmmm I have try whit this script:
Code:@rem unless otherwise specified for debugging reasons turn echo off @if "%EMode%"=="" Set EMode=ON @ECHO %EMode% @ECHO off cls SetLocal DisableDelayedExpansion Set "EXTLIST=*.MXF" Set "DoPop=0" Set "ARGLVL=0" Set "FileName-DQ=" Set VD_LOC="v:\automazioneclip\VirtualDub\vdub.exe" set "DestFolder=." Set "WorkFolder=%DestFolder%" rem process the arguments one by one cls set /p "num= INSERT START NUMERATION: " echo num uguale a %num% set /a num2=%num% echo num2 uguale a %num2% :ARGS color rem if there are no further arguments then exit the batch. if [%1]==[] ( if "%ARGLVL%"=="0" ( CALL :GetTargetName EndLocal pause ) goto :eof ) rem wildcard processing Set "FileName=%~1" if "%FileName%"=="" ( SHIFT goto :ARGS ) rem if the argument doesn't exist in the file system in any form skip it. if NOT EXIST %1 ( SHIFT goto :ARGS ) if NOT [%1]==[] if NOT "%FileName:^*=%%FileName:^?=%"=="%FileName%%FileName%" ( for %%w in (%1) DO ( Set /a ARGLVL+=1 CALL :ARGS "%%~fw" Set /a ARGLVL-=1 ) SHIFT goto :ARGS ) Set "FileName=" rem Set search/recursion variables Set "Pattern=%EXTLIST%" Set "STARTLVL=0" Set "FOUNDLVL=1024" rem if the argument is the current directory then process everything in it. if "%~f1"=="%CD%" ( rem echo Processing Directory "%CD%" CALL :START %1 SHIFT goto :ARGS ) rem Test if the argument is a directory, if it is move to it then process everything in it, if not then move to the file's parent directory and process the file. Then return to starting directory. Type NUL pushd "%~f1" 2> nul if NOT "%errorlevel%"=="0" ( if NOT "%CD%\"=="%~dp1" ( pushd "%~dp1" Set "DoPop=1" ) Set Pattern="%~nx1" ) else ( rem echo Processing Directory "%~f1" Set "DoPop=1" ) CALL :START %1 if "%DoPop%"=="1" ( popd Set "DoPop=0" ) SHIFT goto :ARGS :START <CURRENT_ARG> color rem Count is superseded by FOUNDLVL but may still be useful for renaming purposes Set "Count=0" rem Process all files in the current directory fitting the arguments search pattern. for /F "delims=" %%y in ('dir %Pattern% /b /o:-d /t:w') do ( if /I NOT "%%~y"=="File Not Found" CALL :Process_File "%%~fy" ) rem if it didn't find anything search all directories instead goto :eof if "%Count%"=="0" if %STARTLVL% LSS %FOUNDLVL% ( for /d %%b in (*) do ( pushd "%%~fb" rem echo Processing Directory "%%~fb" Set /a STARTLVL+=1 CALL :START "%%~fb" Set /a STARTLVL-=1 popd ) ) goto :eof :Process_File <FILENAME> color rem *** check if file is MXF Set "TokenS=0" Set "isMXF=0" IF "%~x1"==".MXF" Set "TokenS=1" IF "%~x1"==".mxf" Set "TokenS=1" If "%TokenS%"=="1" Set "isMXF=1" if "%isMXF%"=="1" (CALL :MXFrenaming "%WorkFolder%\%~n1.vcf" "%WorkFolder%\%~n1.avs" "%WorkFolder%\%~n1.avi" "%~f1") echo DONE echo. echo --------------------------------------------- echo. EndLocal goto :eof :MXFrenaming <VCF_FILENAME> <AVS_FILENAME> <FILENAME> <ORG_FILENAME> echo *** MXF renaming routine *** echo processing "%~dp1%~n1.MXF" echo percorso del myfiletxt uguale a "%~dp1%myfiles.txt" if exist myfiles.txt del myfiles.txt dir *.mxf /a-d /b >myfiles.txt md "%~dp1tempbatchprocess" for /f "tokens=* delims= " %%a in (myfiles.txt) do type nul >"%~dp1tempbatchprocess\%%~na.cam" for /L %%a in (%num2%,1,999) do ( if not exist "%~dp1tempbatchprocess\C0%%a.cam" if not exist "%~dp1C0%%a.mxf" (ren "%~dp1%~n1.MXF" "C0%%a.MXF" if exist "%~dp1C0%%a.mxf" set "FilenameForCameraOnline=%~dp1C0%%a.mxf">"%~n1"_renamed_in_"C0%%a_MXF".log) ) ) if exist "%~dp1tempbatchprocess" RD /S /q "%~dp1tempbatchprocess" if exist myfiles.txt del myfiles.txt cls goto :eof :GetTargetName color Set "FileName=" Set /p FileName=InputFileName rem Add or remove double-quotes if necessary if NOT DEFINED FileName ( Set "FileName-DQ=" goto :DQSkip ) Set "FileName-DQ=%FileName:"=%" if NOT DEFINED FileName-DQ ( Set "FileName=" Set "FileName-DQ=" goto :DQSkip ) if EXIST "%FileName-DQ%" ( if "%FileName-DQ%"=="%FileName-DQ: =%" ( Set "FileName=%FileName-DQ%" ) else ( Set FileName="%FileName-DQ%" ) ) :DQSkip color if /I "%FileName-DQ%"=="" Set FileName="%CD%" if /I "%FileName-DQ%"=="CD" Set FileName="%CD%" if /I "%FileName-DQ%"=="EXIT" goto :eof if /I "%FileName-DQ%"=="NOEXIT" goto :GetTargetName if DEFINED FileName ( Set /a ARGLVL+=1 CALL :ARGS %FileName% Set /a ARGLVL-=1 ) goto :GetTargetName
but there are 2 particular case:
case 1) if the number of start is between 10 and 99
case 2) if the number of start is between 0 and 9 -
for example I would like rename this first 10 files selected, starting from C0104
[Attachment 34730 - Click to enlarge]
the new batch produce this correct result:
[Attachment 34731 - Click to enlarge]
but if the start is a number between 10 and 99 - for example 85 - the result is:
[Attachment 34732 - Click to enlarge]
or f the start is a number between 0 and 9 - for example 5 - the result is:
[Attachment 34733 - Click to enlarge]
So I need add little enhancement to the batch so that:
if the lenght of the final renamed file is of 3 characters ----> add 2 zero after the "C" so that the final result is C0005.MXF
if the lenght of the final renamed file is of 4 characters ----> add 1 zero after the "C" so that the final result is C0085.MXF -
Code:
@rem unless otherwise specified for debugging reasons turn echo off @if "%EMode%"=="" Set EMode=ON @ECHO %EMode% @ECHO off cls SetLocal DisableDelayedExpansion Set "EXTLIST=*.MXF" Set "DoPop=0" Set "ARGLVL=0" Set "FileName-DQ=" Set VD_LOC="v:\automazioneclip\VirtualDub\vdub.exe" set "DestFolder=." Set "WorkFolder=%DestFolder%" rem process the arguments one by one cls set /p "num= INSERT start enumeration: " echo num uguale a %num% set /a num2=%num%/1 echo num2 uguale a %num2% :ARGS color rem if there are no further arguments then exit the batch. if [%1]==[] ( if "%ARGLVL%"=="0" ( CALL :GetTargetName EndLocal pause ) goto :eof ) rem wildcard processing Set "FileName=%~1" if "%FileName%"=="" ( SHIFT goto :ARGS ) rem if the argument doesn't exist in the file system in any form skip it. if NOT EXIST %1 ( SHIFT goto :ARGS ) if NOT [%1]==[] if NOT "%FileName:^*=%%FileName:^?=%"=="%FileName%%FileName%" ( for %%w in (%1) DO ( Set /a ARGLVL+=1 CALL :ARGS "%%~fw" Set /a ARGLVL-=1 ) SHIFT goto :ARGS ) Set "FileName=" rem Set search/recursion variables Set "Pattern=%EXTLIST%" Set "STARTLVL=0" Set "FOUNDLVL=1024" rem if the argument is the current directory then process everything in it. if "%~f1"=="%CD%" ( rem echo Processing Directory "%CD%" CALL :START %1 SHIFT goto :ARGS ) rem Test if the argument is a directory, if it is move to it then process everything in it, if not then move to the file's parent directory and process the file. Then return to starting directory. Type NUL pushd "%~f1" 2> nul if NOT "%errorlevel%"=="0" ( if NOT "%CD%\"=="%~dp1" ( pushd "%~dp1" Set "DoPop=1" ) Set Pattern="%~nx1" ) else ( rem echo Processing Directory "%~f1" Set "DoPop=1" ) CALL :START %1 if "%DoPop%"=="1" ( popd Set "DoPop=0" ) SHIFT goto :ARGS :START <CURRENT_ARG> color rem Count is superseded by FOUNDLVL but may still be useful for renaming purposes Set "Count=0" rem Process all files in the current directory fitting the arguments search pattern. for /F "delims=" %%y in ('dir %Pattern% /b /o:-d /t:w') do ( if /I NOT "%%~y"=="File Not Found" CALL :Process_File "%%~fy" ) rem if it didn't find anything search all directories instead goto :eof if "%Count%"=="0" if %STARTLVL% LSS %FOUNDLVL% ( for /d %%b in (*) do ( pushd "%%~fb" rem echo Processing Directory "%%~fb" Set /a STARTLVL+=1 CALL :START "%%~fb" Set /a STARTLVL-=1 popd ) ) goto :eof :Process_File <FILENAME> color rem *** check if file is MXF Set "TokenS=0" Set "isMXF=0" IF "%~x1"==".MXF" Set "TokenS=1" IF "%~x1"==".mxf" Set "TokenS=1" If "%TokenS%"=="1" Set "isMXF=1" if "%isMXF%"=="1" (CALL :MXFrenaming "%WorkFolder%\%~n1.vcf" "%WorkFolder%\%~n1.avs" "%WorkFolder%\%~n1.avi" "%~f1") echo DONE echo. echo --------------------------------------------- echo. EndLocal goto :eof :MXFrenaming <VCF_FILENAME> <AVS_FILENAME> <FILENAME> <ORG_FILENAME> echo *** MXF renaming routine *** echo processing "%~dp1%~n1.MXF" echo percorso del myfiletxt uguale a "%~dp1%myfiles.txt" if exist myfiles.txt del myfiles.txt dir *.mxf /a-d /b >myfiles.txt md "%~dp1tempbatchprocess" for /f "tokens=* delims= " %%a in (myfiles.txt) do type nul >"%~dp1tempbatchprocess\%%~na.cam" for /L %%a in (%num%,1,999) do ( if not exist "%~dp1tempbatchprocess\C0%%a.cam" if not exist "%~dp1C0%%a.mxf" if not exist "%~dp1C00%%a.mxf" if not exist "%~dp1C000%%a.mxf" (ren "%~dp1%~n1.MXF" "C0%%a.MXF" if exist "%~dp1C0%%a.mxf" set "FilenameForCameraOnline=C0%%a">"%~n1"_renamed_in_"C0%%a.MXF".log) ) ) set file=%FilenameForCameraOnline%.MXF for %%f in (%file%) do set "filename=%%~nf" echo old file: %filename% if "%filename:~2,1%"=="" goto skip if "%filename:~4,1%"=="" goto renfile goto skip :renfile if "%filename:~3,1%"=="" goto renfile3 set "newfile=%file:~0,1%0%file:~1%" ren %file% %newfile% ren "%~n1_renamed_in_%FilenameForCameraOnline%.mxf.log" "%~n1_renamed_in_%newfile%.log" goto done :renfile3 set "newfile=%file:~0,1%00%file:~1%" ren %file% %newfile% ren "%~n1_renamed_in_%FilenameForCameraOnline%.mxf.log" "%~n1_renamed_in_%newfile%.log" goto done :skip :done if exist "%~dp1tempbatchprocess" RD /S /q "%~dp1tempbatchprocess" if exist myfiles.txt del myfiles.txt cls goto :eof :GetTargetName color Set "FileName=" Set /p FileName=InputFileName rem Add or remove double-quotes if necessary if NOT DEFINED FileName ( Set "FileName-DQ=" goto :DQSkip ) Set "FileName-DQ=%FileName:"=%" if NOT DEFINED FileName-DQ ( Set "FileName=" Set "FileName-DQ=" goto :DQSkip ) if EXIST "%FileName-DQ%" ( if "%FileName-DQ%"=="%FileName-DQ: =%" ( Set "FileName=%FileName-DQ%" ) else ( Set FileName="%FileName-DQ%" ) ) :DQSkip color if /I "%FileName-DQ%"=="" Set FileName="%CD%" if /I "%FileName-DQ%"=="CD" Set FileName="%CD%" if /I "%FileName-DQ%"=="EXIT" goto :eof if /I "%FileName-DQ%"=="NOEXIT" goto :GetTargetName if DEFINED FileName ( Set /a ARGLVL+=1 CALL :ARGS %FileName% Set /a ARGLVL-=1 ) goto :GetTargetName
Last edited by marcorocchini; 6th Dec 2015 at 04:05.
Similar Threads
-
BATCH processing: how to process also subfolders? ndjamena help please :)
By marcorocchini in forum Newbie / General discussionsReplies: 2Last Post: 4th Dec 2015, 18:42 -
Ndjamena please can u see my batch?
By marcorocchini in forum Newbie / General discussionsReplies: 0Last Post: 7th Jul 2014, 08:34 -
Batch processing all my video files.
By Paxmilitaris in forum Newbie / General discussionsReplies: 1Last Post: 25th Mar 2013, 16:43 -
Tool to batch download, save and rename QuickTime stream files
By oediv in forum Video Streaming DownloadingReplies: 8Last Post: 24th Dec 2011, 17:24 -
Batch Processing 2.34:1 AVCHD Files for preview
By goanna300 in forum Video ConversionReplies: 17Last Post: 28th Jun 2011, 01:45