Page 1 of 1

Need help on DIR command

Posted: 17 Feb 2009 13:13
by DOSThings
Hi All,

I am quite new to DOS programming. I am currently stuck with a problem which I am sure many of you already know.
My requirement is to get the list of all folders and sub-folders in relative path format.

For example, the command "DIR C:\DRIVERS /s /B /A:D" lists down all the folders and sub-folders present under C:\DRIVERS. However, all these are fully qualified:

C:\DRIVERS\AUDIO
C:\DRIVERS\FPR
C:\DRIVERS\LPM
C:\DRIVERS\WLLANBCM
C:\DRIVERS\AUDIO\SMAXWDM
C:\DRIVERS\AUDIO\Sys
C:\DRIVERS\AUDIO\SMAXWDM\W2K_XP

What I want is as follows -

\AUDIO
\FPR
\LPM
\WLLANBCM
\AUDIO\SMAXWDM
\AUDIO\Sys
\AUDIO\SMAXWDM\W2K_XP

Can I achieve this by using a different form of DIR command or manipulating the 1st list in some way? I need the solution real quick. Any help will be greatly appreciated.


Thanks.

Posted: 17 Feb 2009 15:40
by jaffamuffin
Use the expansion shortcuts.

if %1 is c:\drivers\audio

then %~pn1 is \drivers\audio
and %~n1 is \audio\

etc