Vbscript 读取文件组的文件名,创建具有特定文件名(不包括扩展名)的文件夹,然后将每个文件复制到各自的文件夹中。

Vbscript 读取文件组的文件名,创建具有特定文件名(不包括扩展名)的文件夹,然后将每个文件复制到各自的文件夹中。,vbscript,batch-file,dos,Vbscript,Batch File,Dos,读取文件组的文件名,创建具有特定文件名(不包括扩展名)的文件夹,然后将每个文件复制到各自的文件夹中。 我试过这个,但效果不好 @echo off for /F "tokens=1 delims =_" %%G in ('dir/b *.txt') do set testvariable=%%G md %testvariable% set "path=C:\Documents and Settings\USP\Desktop\" set

读取文件组的文件名,创建具有特定文件名(不包括扩展名)的文件夹,然后将每个文件复制到各自的文件夹中。 我试过这个,但效果不好

      @echo off
      for /F "tokens=1 delims =_" %%G in ('dir/b *.txt') do set testvariable=%%G
      md %testvariable%
      set "path=C:\Documents and Settings\USP\Desktop\"
      set "path2=%testvariable%"
      set "destpath=%path%%path2%"
      copy *.txt %destpath% 

您无法在同一位置创建与文件同名的文件夹。

亲爱的,上面的代码正在创建文件夹,但问题是没有将文件复制到该文件夹中。……亲爱的,那么您没有按照问题中的说明将文件夹名完全设置为文件名。您是否尝试使用xcopy而不是copy?您是否意识到在
循环的
选项中,delims
=
之间有一个空格?实际脚本中是否也存在空格?
      @echo off
      for /F "tokens=1 delims =_" %%G in ('dir/b *.txt') do set testvariable=%%G
      md %testvariable%
      set "path=C:\Documents and Settings\USP\Desktop\"
      set "path2=%testvariable%"
      set "destpath=%path%%path2%"
      copy *.txt %destpath%