Looping over directories in Windows XP command prompt

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

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

Will give me:


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

echo %i - %j

And the output might be something like:

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

Thanks in advance!


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

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

Using your example, the following command will list directories in the format that you specified:

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

Need Your Help

Shell Script Not Saving File Correctly

linux shell backup

Hey all, I made a backup script and it will save the file but instead of the file being named 01_files.tar.gz or 01_databases.tar.gz all I get is a .tar.gz and then the rest of the script cannot work

maven profile for OS version range

java maven

Is it not possible to define an OS version range in a maven profile?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.