Solved

DOS For In Dir Pass Fullpath?

Posted on 2011-03-11
8
508 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:pointeman
  • 3
  • 3
  • 2
8 Comments
 
LVL 16

Expert Comment

by:sjklein42
ID: 35111178
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
0
 
LVL 51

Accepted Solution

by:
Bill Prew earned 250 total points
ID: 35111935
The way your FRO loop is coded the loop variable will by default be the full path, so it's a simple as:

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

~bp
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 35112003
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

0
 

Author Comment

by:pointeman
ID: 35112347
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
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:pointeman
ID: 35112382
billprew

Yes, it is just that simple (%%~a)... :)
0
 
LVL 16

Assisted Solution

by:sjklein42
sjklein42 earned 250 total points
ID: 35112427
Sorry, forgot the double quotes when calling bat2.

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

Open in new window


%a works most of the time but I find that when I use the %~xxx notation to extract just particular parts of the filename, it sometimes gets confused if the letter I use for the variable is also one of the special characters listed in my note above.
0
 

Author Closing Comment

by:pointeman
ID: 35112988
You both helped greatly :)
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 35113674
Welcome.

~bp
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now