2014-02-14 154 views
0
for %%a in (.\*.jpg) do 

上面的代码会将每个jpg图片的名称存储在%% a中,但它存储了带有文件扩展名的全名,例如“Q.jpg”。在批处理脚本中没有扩展名的文件名

我使用调整图像大小一个cmd程序,

resize /width:100 %%a %%a.jpg 

这将调整“Q.jpg”然后将其命名为“Q.jpg.jpg”,你可以看到扩展名是现在是文件名的一部分!

我想避免它。

+1

有对文件名部分http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx?mfr=true我想你可以使用许多扩展“% 〜N1" – dandavis

+1

如果你有长文件名,然后用双引号围绕%%一个在'‘%%一个’'和'‘%%〜na.jpg’'等等。你可能会发现,现在的源和目标名称是相同的,但可能会损坏源文件。 – foxidrive

回答

3

简单,输入/?更多信息:

只获取文件名:

for %%a in (.\*.jpg) do resize /width:100 %%a %%~na.jpg 

引用Windows批处理帮助(类型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 

这应该会帮助你解决任何问题。

+0

@KenWhite:让我们不要在这里过分敏感。这是事实。 –

+1

希望我能读到这里发生的事情。这个消息听起来就像感觉受到伤害。 – unclemeat

相关问题