Quanti Monati
Quanti Monati

Reputation: 811

Using file-name as parameter in batch file

I have something like this

FOR %%A IN ("Drawings\*.txt") DO draw.exe /f %%A /d ONLY_FILENAME

But I need to put file-name of each txt-file automatically into the string as "/d ..." parameter.

Example: I have file "The First File.txt" in my Drawings directory. And the automatically generated string have to be like this one

FOR %%A IN ("Drawings\*.txt") DO 

draw.exe /f "Drawings\The First File.txt" /d "The First File"

How to do that?

Upvotes: 1

Views: 476

Answers (1)

npocmaka
npocmaka

Reputation: 57252

FOR %%A IN ("Drawings\*.txt") DO draw.exe /f "%%A" /d "%%~nA"

?

Here's an excerpt from FOR help:

In addition, substitution of FOR variable references has been enhanced
You can now use the following optional syntax:

%~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

Upvotes: 1

Related Questions