Solved

DOS For In Dir Pass Fullpath?

Posted on 2011-03-11
8
515 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 52

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 52

Expert Comment

by:Bill Prew
ID: 35113674
Welcome.

~bp
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

919 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

16 Experts available now in Live!

Get 1:1 Help Now