(使用批处理文件)仅将文件名存入For循环

时间:2018-07-21 00:45:09

标签: batch-file

这是根据您的评论的新版本。 它仍然不起作用。

我尝试重命名类似文件

  • 2006年Gaspésie-Croisièreàla baleine 1023.jpg
  • 2006年Gaspésie-Croisièrebaleine 28.jpg

收件人

  • 2006-06Croisièrebaleine 001.jpg
  • 2006-06Croisièrebaleine 002.jpg

问题是当我回显和重命名时,字段F1和F2为空。

@echo off
setlocal ENABLEDELAYEDEXPANSION

set /p "NewFileName=New name file (without the extension): "
set /p "LenghtMask=Mask lenght of the number: "
set /a FileNo=0

for %%I in (*.JPG) do (
echo.

@echo off
set /a FileNo=!FileNo!+1
call :return_no_mask !FileNo! %LenghtMask% FileNoMask
@echo on

set "F1=%%~I"
echo F1   %F1%

set ExtensionName=%%~xI
set "F2=%NewFileName% %FileNoMask%%ExtensionName%"
echo F2   %F2%

rename "%F1%" "%F2%"
pause
)
goto:EOF


::--------------------------------------------------
::Return the number (fill with 0 to have the right lenght)
:: in  Number to use
:: in  Mask's lenght ex: 2
:: out Number
::--------------------------------------------------
:return_no_mask
set NoIn=%1

::---Search the lenght of the number
set /a LenghtNo=1
if "%NoIn%" GEQ "10" set /a LenghtNo=2
if "%NoIn%" GEQ "100" set /a LenghtNo=3
if "%NoIn%" GEQ "1000" set /a LenghtNo=4
if "%NoIn%" GEQ "10000" set /a LenghtNo=5

::---Fill with zero
set NoOut=
:test_add
if "%LenghtNo%" LSS "%2" (
set NoOut=0%NoOut%
set /a LenghtNo+=1
goto :test_add
)
set NoOut=%NoOut%%1

set %3=%NoOut%
EXIT /B 0

::--------------------------------------------------
::End of file
::--------------------------------------------------
:EOF
endlocal

谢谢

0 个答案:

没有答案