Based on some other answers I found, I can loop through available drive labels. However, I can't seem to change to that drive:
for /f "skip=1 delims=" %%x in ('wmic logicaldisk get caption') do (
%%x
dir
)
Which gives me:
PS C:\> .\something.bat
C:\>for /F "skip=1 delims=" %x in ('wmic logicaldisk get caption') do (
%x
dir
)
C:\>(
:
dir
)
The filename, directory name, or volume label syntax is incorrect.
Volume in drive C has no label.
Volume Serial Number is 9CE0-91A0
Directory of C:\
07/14/2018 09:54 AM 1,586 compact-all.bat
06/25/2018 01:03 PM <JUNCTION> Documents and Settings [C:\Users]
07/14/2018 08:03 AM <DIR> Fraps
06/25/2018 01:07 PM <DIR> Intel
06/25/2018 02:18 PM <DIR> NVIDIA
04/11/2018 05:38 PM <DIR> PerfLogs
07/13/2018 08:32 AM <DIR> Program Files
07/13/2018 04:56 PM <DIR> Program Files (x86)
06/25/2018 02:12 PM <DIR> Python27
07/14/2018 12:26 PM 7,404 result.txt
07/14/2018 12:26 PM 83 something.bat
06/25/2018 01:08 PM <DIR> Users
06/30/2018 02:19 PM <DIR> Windows
3 File(s) 9,073 bytes
10 Dir(s) 84,364,111,872 bytes free
C:\>(
:
dir
)
The filename, directory name, or volume label syntax is incorrect.
Volume in drive C has no label.
Volume Serial Number is 9CE0-91A0
Directory of C:\
07/14/2018 09:54 AM 1,586 compact-all.bat
06/25/2018 01:03 PM <JUNCTION> Documents and Settings [C:\Users]
07/14/2018 08:03 AM <DIR> Fraps
06/25/2018 01:07 PM <DIR> Intel
06/25/2018 02:18 PM <DIR> NVIDIA
04/11/2018 05:38 PM <DIR> PerfLogs
07/13/2018 08:32 AM <DIR> Program Files
07/13/2018 04:56 PM <DIR> Program Files (x86)
06/25/2018 02:12 PM <DIR> Python27
07/14/2018 12:26 PM 7,404 result.txt
07/14/2018 12:26 PM 83 something.bat
06/25/2018 01:08 PM <DIR> Users
06/30/2018 02:19 PM <DIR> Windows
3 File(s) 9,073 bytes
10 Dir(s) 84,364,111,872 bytes free
C:\>(
:
dir
)
The device is not ready.
Volume in drive C has no label.
Volume Serial Number is 9CE0-91A0
Directory of C:\
07/14/2018 09:54 AM 1,586 compact-all.bat
06/25/2018 01:03 PM <JUNCTION> Documents and Settings [C:\Users]
07/14/2018 08:03 AM <DIR> Fraps
06/25/2018 01:07 PM <DIR> Intel
06/25/2018 02:18 PM <DIR> NVIDIA
04/11/2018 05:38 PM <DIR> PerfLogs
07/13/2018 08:32 AM <DIR> Program Files
07/13/2018 04:56 PM <DIR> Program Files (x86)
06/25/2018 02:12 PM <DIR> Python27
07/14/2018 12:26 PM 7,404 result.txt
07/14/2018 12:26 PM 83 something.bat
06/25/2018 01:08 PM <DIR> Users
06/30/2018 02:19 PM <DIR> Windows
3 File(s) 9,073 bytes
10 Dir(s) 84,364,111,872 bytes free
C:\>(
dir
)
Volume in drive C has no label.
Volume Serial Number is 9CE0-91A0
Directory of C:\
07/14/2018 09:54 AM 1,586 compact-all.bat
06/25/2018 01:03 PM <JUNCTION> Documents and Settings [C:\Users]
07/14/2018 08:03 AM <DIR> Fraps
06/25/2018 01:07 PM <DIR> Intel
06/25/2018 02:18 PM <DIR> NVIDIA
04/11/2018 05:38 PM <DIR> PerfLogs
07/13/2018 08:32 AM <DIR> Program Files
07/13/2018 04:56 PM <DIR> Program Files (x86)
06/25/2018 02:12 PM <DIR> Python27
07/14/2018 12:26 PM 7,404 result.txt
07/14/2018 12:26 PM 83 something.bat
06/25/2018 01:08 PM <DIR> Users
06/30/2018 02:19 PM <DIR> Windows
3 File(s) 9,073 bytes
10 Dir(s) 84,364,111,872 bytes free
PS C:\>
But what I want is it to go to drive c:, d:, etc. and run a command.
I know normally I could do something like
dir %%x
but I'm making a script to compress (compact) the contents of every drive, but it doesn't seem to take the parameter correctly as it doesn't go through all the files when I do:
compact d:
which only affect the root of d:
versus
d:
compact
which affects every file and directory on d:
compact /?
or view ss64.com/nt/compact.html