How can I suppress filename extensions at the command line interpreter and batch files?

回眸只為那壹抹淺笑 提交于 2019-12-24 15:06:12

问题


Example: I have a file: FILENAME.EXT and would like to extract FILENAME without the .EXT I want to be able to use the extensionless filename for a command which only accepts filenames without its extensions. I have a utility called BCHECK which accepts as its argument a filename with no extensions. Using BCHECK *. does not work because all the files have .DAT or .IDX extensions. These files are constantly being renamed, thus I need to provide BCHECK with the new filenames without having to manually enter them.


回答1:


The Unix command for this is basename.




回答2:


For DOS batch files you can look at parameters here. For example, the following command displays the filename without extension for the 0 parameter, which is the name of the batch file.

echo %~n0

UPDATE:
Here's an example that can be added to a batch file.

FOR %%f IN (*.dat) DO bcheck -y %%~nf

This command will run bcheck -y BASENAME for each file with a .dat extension in the current directory. The command is a for loop that contains a parameter %%f. The %%f parameter contains the file's full name. For each file matching *.dat, it will run the command after the DO keyword. The %%~nf indicates to to use the basename (~n) from the parameter (%%f).



来源:https://stackoverflow.com/questions/3429032/how-can-i-suppress-filename-extensions-at-the-command-line-interpreter-and-batch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!