z tym, że będziesz mógł policzyć liczbę wystąpień "New_Folder *" i utworzyć z kolejnym numerem.
@echo off
set /a count=0
for /d %%d in (New_Folder*) do (
set /a count+=1
)
set /a count+=1
mkdir New_Folder%count%
Należy pamiętać, że najlepszym sposobem byłoby znaleźć największa liczba na koniec New_Folder, ale Windows Batch jest bardzo ograniczające, a ja jestem facetem Linux!
EDIT: Po około jednej godzinie googlowania i testowania:
@echo off
setlocal EnableDelayedExpansion
set max_number=0
for /d %%d in (New_Folder*) do (
set current_directory=%%~nxd
call:StrLength name_length !current_directory!
call:Substring directory_number,!current_directory!,10,!name_length!
if !directory_number! gtr !max_number! (
set max_number=!directory_number!
)
)
set /a max_number+=1
mkdir New_Folder%max_number%
:Substring
::Substring(retVal,string,startIndex,length)
:: extracts the substring from string starting at startIndex for the specified length
SET string=%2%
SET startIndex=%3%
SET length=%4%
if "%4" == "0" goto :noLength
CALL SET _substring=%%string:~%startIndex%,%length%%%
goto :substringResult
:noLength
CALL SET _substring=%%string:~%startIndex%%%
:substringResult
set "%~1=%_substring%"
GOTO :EOF
:StrLength
::StrLength(retVal,string)
::returns the length of the string specified in %2 and stores it in %1
set #=%2%
set length=0
:stringLengthLoop
if defined # (set #=%#:~1%&set /A length += 1&goto stringLengthLoop)
::echo the string is %length% characters long!
set "%~1=%length%"
GOTO :EOF
Uwaga, linia poleceń powrócić mi błąd „Składnia polecenia jest niepoprawna”. ale wszystko działa, więc pozwolę ci znaleźć powód ... Nowy folder jest tworzony niezależnie od kolejności katalogów lub jeśli zaczyna się od 1 lub nie :) Mam nadzieję, że Ci się spodoba!
To się udało! Dzięki wielkie! –
działa jak urok. Dzięki! –