list files from DIR line and hiding extensions (Batch)
Moderator: DosItHelp
-
- Posts: 38
- Joined: 04 Apr 2012 03:11
list files from DIR line and hiding extensions (Batch)
Hi guys,
another connundrum...
Im trying to perform the following command at the prompt:
dir /s /b c:\ojw\completed_album\*.wav
But want to hide the .wav in the results and output to a text file... It seems it's doable...
http://superuser.com/questions/223156/h ... dir-output
but i'll be damned if i can get the working command!
Given the command dir /s /b c:\ojw\completed_album\*.wav can someone generate a working command for me?
another connundrum...
Im trying to perform the following command at the prompt:
dir /s /b c:\ojw\completed_album\*.wav
But want to hide the .wav in the results and output to a text file... It seems it's doable...
http://superuser.com/questions/223156/h ... dir-output
but i'll be damned if i can get the working command!
Given the command dir /s /b c:\ojw\completed_album\*.wav can someone generate a working command for me?
Re: list files from DIR line and hiding extensions (Batch)
Put the dir command in a for /f loop and use the file modifiers to remove the extension and use an echo and redirect the output to a text file.
I believe both the threads you have started have given you examples of this.
I believe both the threads you have started have given you examples of this.
Re: list files from DIR line and hiding extensions (Batch)
Example (untested):
Code: Select all
@echo off
for /f "delims=" %%a in ('dir *.wav /s /b') do echo %%~na
-
- Posts: 38
- Joined: 04 Apr 2012 03:11
Re: list files from DIR line and hiding extensions (Batch)
Hi squashman - The premise is v.similar but i've never removed the file extension from the search which is the key requirement - There is also nothing within the help for dir /? that is obvious that removes the extension.
Foxi - Awesome! Works a treat as always! Thanks!
Foxi - Awesome! Works a treat as always! Thanks!
Re: list files from DIR line and hiding extensions (Batch)
Because you are reading the wrong help. You need to read the help for the FOR command. The file modifiers have now been used in all 3 of the scripts that Foxi has written for you. Are you not going thru the code and understanding how it all works?
Re: list files from DIR line and hiding extensions (Batch)
Squashman wrote: Are you not going thru the code and understanding how it all works?
I don't know about phoenix_Rising but I think a lot of people tend to use a script and seldom delve deeply into what is going on in the innards.
It's when they make a small change and 'it works!' that some of them would become curious and they get their hands dirty and get 'into' the enjoyment of scripts.
For many it's too arcane and convoluted and they just want to job done.
That's how it appears to me, and from my own experience in some fields.
Last edited by foxidrive on 15 Apr 2012 08:19, edited 1 time in total.
-
- Posts: 38
- Joined: 04 Apr 2012 03:11
Re: list files from DIR line and hiding extensions (Batch)
Thanks - I am v.interested... but not as gifted as some of you guys with understanding the exact science behind every command.... I get the gist of whats going on and in most cases its a small mistake in a command that trips me up... I think it takes time to really understand what's going on and only by utilizing working example code can you sometimes understand WHY it works.
On the same subject, Is it possible to use combinations of the tilda modifiers to get for example the full pathname and file WITHOUT the file extension?
c:\ojw\completed_album\test album\test album - track1
as oposed to:
c:\ojw\completed_album\test album\test album - track1.wav
I had a flick through the modifiers here but was under the understandint aht you could only use one of them in a command as the second mofifier would cancel the first out??
http://weblogs.asp.net/jgalloway/archiv ... batch.aspx
On the same subject, Is it possible to use combinations of the tilda modifiers to get for example the full pathname and file WITHOUT the file extension?
c:\ojw\completed_album\test album\test album - track1
as oposed to:
c:\ojw\completed_album\test album\test album - track1.wav
I had a flick through the modifiers here but was under the understandint aht you could only use one of them in a command as the second mofifier would cancel the first out??
http://weblogs.asp.net/jgalloway/archiv ... batch.aspx
Last edited by phoenix_Rising on 15 Apr 2012 08:22, edited 1 time in total.
Re: list files from DIR line and hiding extensions (Batch)
%%~dpna
That is Drive letter, path, and name of file. a is the variable name, and is case sensitive.
That is Drive letter, path, and name of file. a is the variable name, and is case sensitive.
-
- Posts: 38
- Joined: 04 Apr 2012 03:11
Re: list files from DIR line and hiding extensions (Batch)
I'll try and work it now ... Thanks foxi.. 

-
- Posts: 38
- Joined: 04 Apr 2012 03:11
Re: list files from DIR line and hiding extensions (Batch)
That seems to have done it - The only issue i have is that for some reasen it dosn't capture special characters... so i need a way of ignoring them prior to capturing this data for example running the command i get:
c:\OJW\COMPLETED_ALBUM\Test Album\Accuser - Burn
when i should get:
c:\OJW\COMPLETED_ALBUM\brian setzer.zip\Accuser - Burn!
Is there a little bit of pre-written code for times like this when you need to ignore all the special characters and simply take them as normal characters?
c:\OJW\COMPLETED_ALBUM\Test Album\Accuser - Burn
when i should get:
c:\OJW\COMPLETED_ALBUM\brian setzer.zip\Accuser - Burn!
Is there a little bit of pre-written code for times like this when you need to ignore all the special characters and simply take them as normal characters?
Re: list files from DIR line and hiding extensions (Batch)
Don't use delayedexpansion and you will get the ! characters.
Other characters which may cause issues are ^ and %
Other characters which may cause issues are ^ and %
Re: list files from DIR line and hiding extensions (Batch)
phoenix_Rising wrote:That seems to have done it - The only issue i have is that for some reasen it dosn't capture special characters... so i need a way of ignoring them prior to capturing this data for example running the command i get:
foxidrive wrote:Don't use delayedexpansion and you will get the ! characters.
Other characters which may cause issues are ^ and %
If you only want to echo the filenames foxidrives trick will work.
Aslo ^ and % will work.
But if you want to work with the name a bit inside your loop,
you can use the delayed toggling technic.
Code: Select all
@echo off
setlocal DisableDelayedExpansion
for /f "delims=" %%a in ('dir *.wav /s /b') do (
set "file=%%~na"
setlocal EnableDelayedExpansion
set "file=!file:~0,4!"
echo(!file!
endlocal
)
This works, as the set-statement ( set "file=%%~na") is safe, when delayed expansion is disabled.
And working with variables is only safe, when delayed expansion is enabled.
jeb
-
- Posts: 38
- Joined: 04 Apr 2012 03:11
Re: list files from DIR line and hiding extensions (Batch)
Thanks guys...
I will be referring to the data within a loop..
I have the following code that works for me but dosnt record the special characters...
:ENCODE_APE
echo off
setlocal enabledelayedexpansion
cls
echo.
echo Now encoding...
echo.
if exist %DRIVE%\ojw\logs\ENCODE_LIST.TXT (del /q %DRIVE%\ojw\logs\ENCODE_LIST.TXT) else (echo file not found!)
if exist %DRIVE%\ojw\logs\ENCODE.bat (del /q %DRIVE%\ojw\logs\ENCODE.bat) else (echo file not found!)
for /f "delims=" %%a in ('dir %DRIVE%\ojw\completed_album\*.wav /s /b') do echo %%~dpna>>%DRIVE%\ojw\logs\ENCODE_LIST.txt
for /f "delims=" %%a in (%DRIVE%\ojw\logs\ENCODE_LIST.txt) do echo %DRIVE%\OJW\Tools\mac.exe "%%a.wav" "%%a.ape" -c3000>>%DRIVE%\ojw\logs\ENCODE.bat
CALL %DRIVE%\ojw\logs\ENCODE.bat
I've tried working the example code into this code so that it records the special characters but to no joy... can anyone take a look at patching it up so it records the special characters??
I will be referring to the data within a loop..
I have the following code that works for me but dosnt record the special characters...
:ENCODE_APE
echo off
setlocal enabledelayedexpansion
cls
echo.
echo Now encoding...
echo.
if exist %DRIVE%\ojw\logs\ENCODE_LIST.TXT (del /q %DRIVE%\ojw\logs\ENCODE_LIST.TXT) else (echo file not found!)
if exist %DRIVE%\ojw\logs\ENCODE.bat (del /q %DRIVE%\ojw\logs\ENCODE.bat) else (echo file not found!)
for /f "delims=" %%a in ('dir %DRIVE%\ojw\completed_album\*.wav /s /b') do echo %%~dpna>>%DRIVE%\ojw\logs\ENCODE_LIST.txt
for /f "delims=" %%a in (%DRIVE%\ojw\logs\ENCODE_LIST.txt) do echo %DRIVE%\OJW\Tools\mac.exe "%%a.wav" "%%a.ape" -c3000>>%DRIVE%\ojw\logs\ENCODE.bat
CALL %DRIVE%\ojw\logs\ENCODE.bat
I've tried working the example code into this code so that it records the special characters but to no joy... can anyone take a look at patching it up so it records the special characters??
Re: list files from DIR line and hiding extensions (Batch)
phoenix_Rising wrote:Thanks guys...
I will be referring to the data within a loop..
I have the following code that works for me but dosnt record the special characters...
:ENCODE_APE
echo off
setlocal enabledelayedexpansion
cls
echo.
echo Now encoding...
echo.
if exist %DRIVE%\ojw\logs\ENCODE_LIST.TXT (del /q %DRIVE%\ojw\logs\ENCODE_LIST.TXT) else (echo file not found!)
if exist %DRIVE%\ojw\logs\ENCODE.bat (del /q %DRIVE%\ojw\logs\ENCODE.bat) else (echo file not found!)
for /f "delims=" %%a in ('dir %DRIVE%\ojw\completed_album\*.wav /s /b') do echo %%~dpna>>%DRIVE%\ojw\logs\ENCODE_LIST.txt
for /f "delims=" %%a in (%DRIVE%\ojw\logs\ENCODE_LIST.txt) do echo %DRIVE%\OJW\Tools\mac.exe "%%a.wav" "%%a.ape" -c3000>>%DRIVE%\ojw\logs\ENCODE.bat
CALL %DRIVE%\ojw\logs\ENCODE.bat
I've tried working the example code into this code so that it records the special characters but to no joy... can anyone take a look at patching it up so it records the special characters??
Delete the line above.
-
- Posts: 38
- Joined: 04 Apr 2012 03:11
Re: list files from DIR line and hiding extensions (Batch)
Works a charm! Thanks Foxi