2016-03-02 89 views
1

目前我的循環讀取包含的文件(以.al結尾)。 但是,當我嘗試設置/更改文件名稱時,它只是跳到最終文件並使用該文件。 (xxx.al) 我試圖使用EnableDelayedExpansion但仍無法解析。 最終的輸出應如下Windows批處理:在對每個文件執行操作時遍歷文件名?

spconv -if raw -of wav xxx.al xxx.wav 

但不是隻是xxx.al文件,包含了所有的文件,應通過迭代。即

spconv -if raw -of wav abc.al abc.wav 
spconv -if raw -of wav def.al def.wav 

當前批處理命令如下

@echo off 

for %%d in (*.al) do (
set str=%%d 
set string=%%d:C:\test\test\=% 
set string2=%string:.al=% 
spconv -if raw -of wav %string% %string2%.wav 
) 

回答

2
for %%d in (*.al) do spconv -if raw -of wav %%d %~nd.wav 

看到for /? - 尤其是它的最後一部分。

+0

謝謝您的幫助! –

0

for /?在命令行中提供了有關此語法的幫助。

此外,FOR 變量引用的替換已得到增強。 您現在可以使用以下可選 語法:

%~I   - expands %I removing any surrounding quotes (") 
%~fI  - expands %I to a fully qualified path name 
%~dI  - expands %I to a drive letter only 
%~pI  - expands %I to a path only 
%~nI  - expands %I to a file name only 
%~xI  - expands %I to a file extension only 
%~sI  - expanded path contains short names only 
%~aI  - expands %I to file attributes of file 
%~tI  - expands %I to date/time of file 
%~zI  - expands %I to size of file 
%~$PATH:I - searches the directories listed in the PATH 
       environment variable and expands %I to the 
       fully qualified name of the first one found. 
       If the environment variable name is not 
       defined or the file is not found by the 
       search, then this modifier expands to the 
       empty string 

的修飾符可以結合使用來獲得 複合結果:

%~dpI  - expands %I to a drive letter and path only 
%~nxI  - expands %I to a file name and extension only 
%~fsI  - expands %I to a full path name with short names only 
%~dp$PATH:I - searches the directories listed in the PATH 
       environment variable for %I and expands to the 
       drive letter and path of the first one found. 
%~ftzaI  - expands %I to a DIR like output line 

在上面的例子中,%I和PATH可以 其他替代有效值。 %〜語法由一個有效的 FOR變量名終止。採用大寫字母 像%I這樣的變量名使其更易讀 ,並避免與 修飾符混淆,而這些修飾符並非 敏感。

有不同的字母,你可以用這樣f爲「全路徑名」,d的驅動器盤符,p的路徑,也可以組合使用。 %~是每個序列的開始,並且數字I表示它在參數%I上工作(其中%0是批處理文件的完整名稱,就像您所假設的那樣)。

在批處理文件中,您應該編寫%%I而不是%I來轉義% 字符。

和批量看起來像這樣的:

@echo off 
for %%I in (*.al) do spconv -if raw -of wav %%I %~nI.wav 
Pause 
相關問題