Solved

DOS For In Dir Pass Fullpath?

Posted on 2011-03-11
8
542 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 54

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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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 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 54

Expert Comment

by:Bill Prew
ID: 35113674
Welcome.

~bp
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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