Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 是否可以批量操作文件名?_String_Batch File_Cmd_Path - Fatal编程技术网

String 是否可以批量操作文件名?

String 是否可以批量操作文件名?,string,batch-file,cmd,path,String,Batch File,Cmd,Path,我有一个批处理脚本,可以从路径中查找文件名。 但是,我不需要整个文件名,只需要前六个字符。 我认为下面的脚本可以工作,但它似乎不适用于文件名 set PL=%%~nG set PL=%PL:~0,6% 它返回“~0,6”。,因为您确认此集合在您需要的for循环中 这是发生在for循环内部还是if?在for循环内部。那么您需要延迟扩展 setlocal enableDelayedExpansion for %%G in (something) do ( set PL=%%~nG set

我有一个批处理脚本,可以从路径中查找文件名。 但是,我不需要整个文件名,只需要前六个字符。 我认为下面的脚本可以工作,但它似乎不适用于文件名

set PL=%%~nG
set PL=%PL:~0,6%

它返回“~0,6”。

,因为您确认此
集合在您需要的for循环中


这是发生在for循环内部还是if?在for循环内部。那么您需要延迟扩展
setlocal enableDelayedExpansion

for %%G in (something) do (
  set PL=%%~nG
  set PL=!PL:~0,6!
  echo !PL!
)