Имя пользователя:
Пароль:
 

Показать сообщение отдельно

Пользователь


Сообщения: 122
Благодарности: 6

Профиль | Отправить PM | Цитировать


Похоже нужно на powershell, решение ниже не обрабатывает имена с ! знаками

Код: Выделить весь код
@echo off
setlocal enableextensions enabledelayedexpansion
set "sDestFolder=D:\test"
set "ext=*.txt"

for /f "tokens=*" %%a in ('dir /B /AD %sDestFolder%') do call :action "%%a"

endlocal
exit

:action
set "sSourcePath=%sDestFolder%\%~1"
set "sCountFile="

for /r "%sSourcePath%" %%a in (%ext%) do set /a sCountFile+=1
for /r "%sSourcePath%" %%b in (%ext%) do call :rename "%%b" "%sCountFile%"

exit /b

:rename
:: Ввод: имя файла в директории в sDestFolder

set "sNewNamePart1=!sSourcePath:%sDestFolder%=!"

:: Определяет много файлов или один
if "%~2" LEQ "1" (
set "sNewName=!sNewNamePart1:~1,-1!%~x1"
) else (
set "sNewName=!sNewNamePart1:~1,-1!.%~nx1"
)

if not exist "%~dp1!sNewName!" (
	ren "%~1" "!sNewName!"
)
if not exist "%sDestFolder%\!sNewName!" (
	move "%~dp1!sNewName!" "%sDestFolder%"
)
exit /b

Отправлено: 11:49, 24-11-2015 | #2