The following is the translation:
Regarding the part where delims= in the content, if it is delims=\" I know that \ is used as the delimiter, but what does it mean when there is nothing behind it? I can't figure it out. Hope an expert can explain. Also, please explain the red parts for me? Please.
@echo off&setlocal EnableDelayedExpansion
set a=1
for /f "delims=%%i in ('dir /a-d/b/s *.txt') do (
if not "%%~ni"=="%~n0"
!%%~xi"
set/a a+=1
)
Explanation of red parts:
- "delims=": In the for /f command, delims is used to specify the delimiter. When delims is set to an empty value, it means using the default delimiters, which are spaces, tabs, etc.
- "if not "%%~ni"=="%~n0"": It is an if condition judgment. %%~ni is the name of the current loop variable i, and %~n0 is the name of the current batch file without the extension. It is judging whether the name of the current loop variable i is not equal to the name of the current batch file without the extension.
- "%%~ni!a!%%~xi": %%~ni is the name of the current loop variable i without the extension,!a! is the value of variable a, %%~xi is the extension of the current loop variable i. So it is renaming the file to the name without extension + value of variable a + extension.
Regarding the part where delims= in the content, if it is delims=\" I know that \ is used as the delimiter, but what does it mean when there is nothing behind it? I can't figure it out. Hope an expert can explain. Also, please explain the red parts for me? Please.
@echo off&setlocal EnableDelayedExpansion
set a=1
for /f "delims=%%i in ('dir /a-d/b/s *.txt') do (
if not "%%~ni"=="%~n0"
!%%~xi"
set/a a+=1
)
Explanation of red parts:
- "delims=": In the for /f command, delims is used to specify the delimiter. When delims is set to an empty value, it means using the default delimiters, which are spaces, tabs, etc.
- "if not "%%~ni"=="%~n0"": It is an if condition judgment. %%~ni is the name of the current loop variable i, and %~n0 is the name of the current batch file without the extension. It is judging whether the name of the current loop variable i is not equal to the name of the current batch file without the extension.
- "%%~ni!a!%%~xi": %%~ni is the name of the current loop variable i without the extension,!a! is the value of variable a, %%~xi is the extension of the current loop variable i. So it is renaming the file to the name without extension + value of variable a + extension.
