Link to home
Start Free TrialLog in
Avatar of pointeman
pointemanFlag for United States of America

asked on

DOS For In Dir Pass Fullpath?

Working with two DOS files. Currently I 'pass' the filename.ext to bat2, however I would like to send the entire fullpath.

Help :)

[bat1]
For %%a In ("C:\Program Files\Applications\Files\*.*") Do Call bat2.bat %%~na %%~xa

[bat2]
Echo %1%2
Avatar of sjklein42
sjklein42
Flag of United States of America image

bat1:

Note the ~dpn which give drive and path and name:

I recommend you use the letter "I" instead of "a" for the for loop variable.  It will prevent some issues downstream as "a" already has a meaning.

For %%I In ("C:\temp\*.*") Do Call bat2.bat %%~dpnI %%~xI

Open in new window


    %~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
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think the author wanted the filetype split off and passed as a separate argument from the rest of the file name (and path).  There's a space between the arguments when passed to the bat2.  But you may be right.

PS.  I left my c:\temp testing path in the code when I posted earlier.  Here it is with the right folder:

 For %%I In ("C:\Program Files\Applications\Files\*.*") Do Call bat2.bat %%~dpnI %%~xI 

Open in new window

Avatar of pointeman

ASKER

sjklein42

Q. "a" already has a meaning?

I used you code as is and I receive the following:

Echo C:\Program Files\Applications\Files\filenames......
Echo C:\Program
billprew

Yes, it is just that simple (%%~a)... :)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You both helped greatly :)
Avatar of Bill Prew
Bill Prew

Welcome.

~bp