Navigating directories in the Windows XP command line

I have the following command that will iterate over all subdirectories in a specific location and output the full path:

for /d %i in ("E:\Test\*") do echo %i

      

Give me:

E:\Test\One
E:\Test\Two

      

But how do I get both the full path and just the directory name, so the do command might look something like this:

echo %i - %j

      

And the result might look something like this:

E:\Test\One - One
E:\Test\Two - Two

      

Thanks in advance!

+1


source to share


2 answers


The following command syntax can be used to return only the fully qualified path or directory name:

%~fI        - expands %I to a fully qualified path name
%~nI        - expands %I to a file name only

      



Using your example, the following command will display directories in the specified format:

for /d %i in ("E:\Test*") do echo %~fi - %~ni

      

+4


source


You can use "% ~ ni". This is an extended lookup that will return the path filename (or more precisely, the last part, which is the directory name in your case):

for /d %i in ("E:\Test\*") do echo %i - %~ni

      



See also this question: What does% ~ d0 mean in a Windows batch file?

0


source







All Articles