?
Solved

DOS For In Dir Pass Fullpath?

Posted on 2011-03-11
8
Medium Priority
?
557 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 56

Accepted Solution

by:
Bill Prew earned 1000 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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
 

Author Comment

by:pointeman
ID: 35112382
billprew

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

Assisted Solution

by:sjklein42
sjklein42 earned 1000 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 56

Expert Comment

by:Bill Prew
ID: 35113674
Welcome.

~bp
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month10 days, 15 hours left to enroll

770 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