views:

63

answers:

3

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.

A: 

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

bobs
@bobs: That didn't work in DOS 6.22..I have about 30 files with .DAT extensions in directory C:\DBFILES.. I have a utility called BCHECK.EXE which needs as its argument the basename of the 30 .DAT files, example: 'bcheck -y BASENAME' so can you provide me with a working example?
Frank Computer
@Frank: I added more information to the answer.
bobs
@bobs: Nope, that didn't work within a batch script either, bcheck responded with: File %~nf not found. Remember, this is Pure DOS 6.22 not Windows cmd.exe command interpreter.
Frank Computer
@bobs: Is there any way of subscripting the 8.3 filename like [1,8]?
Frank Computer
@Frank, no, there isn't. Not in DOS, at least.
Joey
So I have looked at several DOS batch utilities and tricks in MGD and other DOS-related websites, but none of these work!.. can anyone think of a clever way for executing a utility which takes as its argument basenames of all files within a directory?
Frank Computer
+1  A: 

The Unix command for this is basename.

Gabe
A: 

So I have looked at several DOS batch utilities and tricks in MGD and other DOS-related websites, but none of these work!.. can anyone think of a clever way for executing a utility which takes as its argument basenames of all files within a directory?..

CAVEAT: Remember, this is native DOS 6.22, not the Windows cmd.exe command interpreter, so %~nx won't work, these are extension in the FOR batch command which are not available in DOS 6.22..

Frank Computer