开发者

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

Example: I hav开发者_如何转开发e 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.


The Unix command for this is basename.


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜