我有此代码,该代码应在目录中保留每个文件名的前30个字符...出于某种原因,该代码不会截断名称。你能帮我理解为什么吗?
cd C:\Users\AGL\Documents\test
for /f "delims=" %%a in ('dir /b /a-d *.csv') do (
set "name=%%~na"
set "ext=%%~xa"
setlocal enabledelayedexpansion
set "nname=!name:~0,-30!"
endlocal
)
pause
答案 0 :(得分:1)
我相信您试图这样做?
@echo off
setlocal enabledelayedexpansion
cd /d "C:\Users\AGL\Documents\test"
for /f "delims=" %%a in ('dir /b /a-d *.csv') do (
set "name=%%~na"
ren "%%~a" "!name:~0,16!%%~xa"
)
pause