Batch file 来自循环的批处理文件名

Batch file 来自循环的批处理文件名,batch-file,for-loop,Batch File,For Loop,我从ftp获取文件。 我需要将每个文件复制到一个新文件夹中,该文件夹将位于文件名的右侧()9个位置 example filename: name_file_decw32014 required foldername: decw32014 当我运行它并将文件名放入变量时,我看不到文件名 @SETLOCAL ENABLEDELAYEDEXPANSION open ftp.il.xxxx.com oren Dev123$ CD D:\oren\ftp binary prompt n mget *

我从ftp获取文件。
我需要将每个文件复制到一个新文件夹中,该文件夹将位于文件名的右侧()9个位置

example filename: name_file_decw32014
required foldername: decw32014
当我运行它并将文件名放入变量时,我看不到文件名

@SETLOCAL ENABLEDELAYEDEXPANSION
open ftp.il.xxxx.com
oren
Dev123$

CD  D:\oren\ftp
binary
prompt n
mget *.xxx

for /R D:\oren\ftp %%i IN (*.xxx*) DO (
 set filename=%%~ni
 set filenameRight=!filename:~0,-9!

 PAUSE
 if not exist "D:\oren\ftp\!filenameRight!" mkdir D:\oren\ftp\!filenameRight!

 copy %%i D:\oren\ftp\!filenameRight!
 pause
 close
 bye
)
filenameRight在运行时不会更改为2014年12月

 set filenameRight=!filename:~0,-9!
应该是

 set filenameRight=!filename:~-9!
子字符串语法是

%var:~start,length% if start >=0 and length >0
%var:~start,endpos% if start >=0 and endpos <0
%var:~start,length% if start <0 and length >0
%var:~start,endpos% if start <0 and endpos <0
%var:~start,如果start>=0且长度>0,则长度为%
%变量:~start,如果start>=0且endpos