hello nnnmmm,
with a FOR /f loop, the whole will be nothing, because the apostrophe can not be processed in the output from the DIR at the loop.
furthermore, this issue will also go into the groats for characters from another codepage.
thus the use of the Delimiter with these filenames is not easily possible.
with a temporary file, this problem also exists.
rename mp3What you can do around this is a FOR loop (without Option /f ) which always prints the name correctly regardless of the codepage set.
You can create the name parts by replacing it with a directory name [\].
the loop is on the fly and can however rename a renamed file again while renaming files and rename at the same time rename and rename.
In order to keep these many small things in mind, a temporary folder is used.
like this script
Code: Select all
@echo OFF
setlocal
set "process=echo ren"
rem set process=ren
set "Folder=d:\mmtest"
set "Files=*.mp3"
set "Recursive=1"
rem Setting Delim
set "Delim= - "
rem this is a temporary Folder for Sorting and renaming only
set "tempFolder=%temp%\nonExistingFolder"
rem use call :seperate with copies for testing
rem call :seperate
if :SUB==only * You want test with seperate Files * & @(
:seperate
rd /s /q "%folder%" 2>nul >nul
md "%folder%"
robocopy /create /mir D:\users\public\music "%folder%" /njh /fp /ndl /nfl /njs
exit /b
)
rem END Settings
rd /s /q "%tempfolder%" 2>nul >nul
md "%tempfolder%"
call :subST_LW Q "%%folder%%"
call :subST_LW R "%%tempfolder%%"
if errorlevel 3 pause &exit /b 1
set Substlist= %Q% %R%
echo temporary Folder is filled ...
robocopy /create /mir %Q% %R% /njh /njs /ndl /nfl
pushD %R%
echo Rename ...
call :process
popD
for %%S in (%SubstList% )do subst /D %%S
rd /S /Q "%tempfolder%"
echo END script
pause
exit /b
:process
for %%F in (%files%)do (
set "fileName=%%F"
setlocal enabledelayedexpansion
for %%X in ("\!filename:%Delim%=\!")do (
endlocal
if NOT exist %Q%%%~pnxF >&2 echo file %Q%%%~pnxF not found!
if exist %Q%%%~pnxF (
for %%U in ("%%~pX.") do %process% "%Q%%%~pnxF" "%%~nX%delim%%%~nxU%%~xX"
)
)
)
if defined recursive (
for /D %%D in (*)do @( pushd %%D
if not errorlevel 1 (
call :process
popD
)
)
)
@exit /b
:subST_LW outVar_LW VarPathToSubst
set "%1="
set "FreeDrive=Z Y X W V U T S R Q P O N M L K J I H G F E D C B A"
for %%i in (%FreeDrive%) do @if not defined %1 >nul subst %%i: %2 &&set %1=%%i:
if not defined %1 1>&2 echo Kein Freies Laufwerk gefunden!& exit /b 3
exit /b
Oh, and
and ask your questions a bit better and grab the few lines of your code so far here to do something to contribute.
Phil