Windows Command Line Help

MisterCornell

Banned
Dec 30, 2004
1,095
0
0
I want to make some m3u files by typing dir /b *.mp3, and sending that output to a file. Is there some way I can do this with cmd?
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
dir /b *.mp3 > blah.m3u

Although I'm not sure of the specific format of m3u files, you'll probably have to do some hand editing to make it work after that.
 

nweaver

Diamond Member
Jan 21, 2001
6,813
1
0
you could batch file it, by echoing the proper stuff before the filename and looping through the dir listing.
 

MisterCornell

Banned
Dec 30, 2004
1,095
0
0
I had one problem. Some of the file names have apostrophe's. CMD outputs an apostrophe as a single quote to the text file. But then Windows can't find the file. Is there a way around this, other than manually editing a bunch of text files?
 

TGS

Golden Member
May 3, 2005
1,849
0
0
Quotes? IIRC there is something fishy about single and double quotes used in a script versus from the prompt.

dir /b "*.mp3" > "blah.m3u"
 

MisterCornell

Banned
Dec 30, 2004
1,095
0
0
Originally posted by: Thyme
Might be less of a headache to do it in perl.

Perl? What are you crazy, I ain't no programmer. :confused:

I can barely do DOS right.

When I type in More, and then the name of the m3u file, it displays the name correctly. Actually I think CMD just doesn't distinguish between single quotes and apostrophes. When I hit the single quote/double quote key in CMD, it displays an apostrophe. But if you cut that and paste it in Windows, it displays as a single quote.
 

networkman

Lifer
Apr 23, 2000
10,436
1
0
dir /b *.mp3 > music.txt

The > is used to re-direct output, be it to a file, a printer, or whatever else. No quotes are needed either in the command line or in a script. I tested it on my machine before posting in case my memory was corrupted. :)

 

TGS

Golden Member
May 3, 2005
1,849
0
0
Originally posted by: networkman
dir /b *.mp3 > music.txt

The > is used to re-direct output, be it to a file, a printer, or whatever else. No quotes are needed either in the command line or in a script. I tested it on my machine before posting in case my memory was corrupted. :)

He says he's having problems with single quotes in the file name. Encapsulation in double quotes should allow him to capture the name, without parsing the single quotes/apostrophes
 

MisterCornell

Banned
Dec 30, 2004
1,095
0
0
Originally posted by: TGS
Originally posted by: networkman
dir /b *.mp3 > music.txt

The > is used to re-direct output, be it to a file, a printer, or whatever else. No quotes are needed either in the command line or in a script. I tested it on my machine before posting in case my memory was corrupted. :)

He says he's having problems with single quotes in the file name. Encapsulation in double quotes should allow him to capture the name, without parsing the single quotes/apostrophes


I've already tried that (dir /b "*.mp3" > "blah.m3u"). These files all have spaces in them, so I was using the quotes to begin with. It runs into the same single quote/apostrophe confusion problem.

C:\Audio\The Beatles - UK Albums (UK+US)\Beatles - 1963 - Please Please Me (UK)>
dir /b "*.mp3"
01 - I Saw Her Standing There.mp3
02 - Misery.mp3
03 - Anna.mp3
04 - Chains.mp3
05 - Boys.mp3
06 - Ask Me Why.mp3
07 - Please Please Me.mp3
08 - Love Me Do.mp3
09 - PS I Love You.mp3
10 - Baby It´s You.mp3 <-- Apostrophe
11 - Do You Want To Know A Secret.mp3
12 - A Taste Of Honey.mp3
13 - There´s A Place.mp3
14 - Twist And Shout.mp3

C:\Audio\The Beatles - UK Albums (UK+US)\Beatles - 1963 - Please Please Me (UK)>
dir /b *.mp3
01 - I Saw Her Standing There.mp3
02 - Misery.mp3
03 - Anna.mp3
04 - Chains.mp3
05 - Boys.mp3
06 - Ask Me Why.mp3
07 - Please Please Me.mp3
08 - Love Me Do.mp3
09 - PS I Love You.mp3
10 - Baby It´s You.mp3 <-- Apostrophe
11 - Do You Want To Know A Secret.mp3
12 - A Taste Of Honey.mp3
13 - There´s A Place.mp3
14 - Twist And Shout.mp3

COMMENT: Using the double quotes for *.mp3 makes no difference, but I use it anyway:

C:\Audio\The Beatles - UK Albums (UK+US)\Beatles - 1963 - Please Please Me (UK)>
dir /b "*.mp3" > temp.m3u

C:\Audio\The Beatles - UK Albums (UK+US)\Beatles - 1963 - Please Please Me (UK)>
more temp.m3u
01 - I Saw Her Standing There.mp3
02 - Misery.mp3
03 - Anna.mp3
04 - Chains.mp3
05 - Boys.mp3
06 - Ask Me Why.mp3
07 - Please Please Me.mp3
08 - Love Me Do.mp3
09 - PS I Love You.mp3
10 - Baby It's You.mp3 <-- Now a single quote
11 - Do You Want To Know A Secret.mp3
12 - A Taste Of Honey.mp3
13 - There's A Place.mp3
14 - Twist And Shout.mp3

C:\Audio\The Beatles - UK Albums (UK+US)\Beatles - 1963 - Please Please Me (UK)>
 

networkman

Lifer
Apr 23, 2000
10,436
1
0
Okay.. color me confused. :confused:

The cmd line I used was also with files that have spaces in the name and there was no issue at all. The names appeared in the text file exactly the way they should.

Edit: Okay, so it's the apostrophe in the name of the song that's presenting a problem?

Edit2: Nope, I'm still confused. I just created a number of files here with file names like "Baby It's You and Baby It's Me" so that I could use the same command I proposed and the output is still exactly what I expect it to be.

Could this be an NTFS vs. FAT32 issue of how file names are handled?
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Where's the apostrophe key?

I don't have one, but some people might. If the filenames are in UTF-8 I believe there is an apostrophe character that is seperate from the single quote.
 

Turge

Junior Member
Aug 22, 2005
4
0
0
Originally posted by: Thyme
Originally posted by: Nothinman
Might be less of a headache to do it in perl.

If only Windows came with a decent scripting language by default.

That'd be fantastic.

It does.. Windows Script Host, or VB Scripting.

Copy and paste the following into a text file with the extension ".VBS" and double-click it

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("c:\")
Set colFiles = objFolder.Files
Const ForAppending = 2
Set objTextFile = objFSO.OpenTextFile ("output.m3u", ForAppending, True)

For Each objFile in colFiles
If right(Ucase(objFile.name),3) = "MP3" then
objTextFile.WriteLine(objFile.Name)
End If
Next

objTextFile.Close

This writes all MP3 filenames from the folder (in this case C:\) to a text file in the same folder as where the script is executed from.
 

Turge

Junior Member
Aug 22, 2005
4
0
0
Originally posted by: Nothinman
It does.. Windows Script Host, or VB Scripting.

IMO VB and JS are not 'decent' languages.

You're right. Batch files are so much more evolved. :roll:

Do you care to back that up with anything? If you don't need a GUI, and need a reliable language to perform quick/administrative tasks, then VB or JS are definately the language of choice on the Windows platform. Throw it into an HTA file and you have a quick web app. Throw some API calls and you can query information on any piece of hardware in your system, change Windows product keys, copy folders and files, move users to different OUs in AD, join domains, create XML files, include proper error handling, etc.
 

networkman

Lifer
Apr 23, 2000
10,436
1
0
I don't particularly care about which language does what, particularly so because I've tested my command line on 3 different rigs(all NTFS) and it's works perfectly on all three of them, spaces, apostropes and whatever else.

Perhaps tomorrow I'll throw together a FAT32 station and see what happens. :roll:

 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
You're right. Batch files are so much more evolved.

Batchfiles are much worse, which is why I said it would be nice if Windows came with a decent scripting language by default.

Do you care to back that up with anything? If you don't need a GUI, and need a reliable language to perform quick/administrative tasks, then VB or JS are definately the language of choice on the Windows platform. Throw it into an HTA file and you have a quick web app. Throw some API calls and you can query information on any piece of hardware in your system, change Windows product keys, copy folders and files, move users to different OUs in AD, join domains, create XML files, include proper error handling, etc.

No doubt there's a lot that you can do with them, but the point is that (other than the fact that I think the languages are ass) VB and JS are overkill, why the hell should I need to learn an OOP language for some basic administration automation? Since I'm a unix guy I do almost all of my scripts in bash and perl and both of them are a lot simpler than VB/JS, especially for extremely simple things like the OP of this thread wanted.