Command.com programming

GEC: Discuss gaming, computers and electronics and venture into the bizarre world of STGODs.

Moderator: Thanas

Post Reply
User avatar
StimNeuro
Padawan Learner
Posts: 444
Joined: 2002-11-11 02:58pm
Location: Marietta, GA

Command.com programming

Post by StimNeuro »

I'm trying to write a program in Command.com to quickly rename all the files in a folder to something that is dependent upon the file name. Unfortunately, I only know how to use higher level languages, like Java and limited C++, so I'm having a rough time just trying to figure out how they do an IF statement. :) Does anyone know of a site where I can find the basics of the Comand.com language? I've tried Googling for it, but havne't turned up anything useful so far. Alternatively, is there a way to do this is Java?
"Well, it's too bad that thread pilots aren't allow to carry pistols.
Otherwise they would have stopped you." - Pablo Sanchez
User avatar
Beowulf
The Patrician
Posts: 10621
Joined: 2002-07-04 01:18am
Location: 32ULV

Post by Beowulf »

Uou want to learn shell scripting? *shudder*

Better idea: get a copy of ActivePerl, and learn perl scripting. Alot more useful, and easier to learn. Plus, you can learn how to do CGI scripting as well...

EDIT: fixed typos...
Last edited by Beowulf on 2004-01-17 03:10am, edited 1 time in total.
"preemptive killing of cops might not be such a bad idea from a personal saftey[sic] standpoint..." --Keevan Colton
"There's a word for bias you can't see: Yours." -- William Saletan
User avatar
Crayz9000
Sith Apprentice
Posts: 7329
Joined: 2002-07-03 06:39pm
Location: Improbably superpositioned
Contact:

Post by Crayz9000 »

It's called a DOS batch script, look it up. And the syntax that goes with it is HORRIBLY limited.
A Tribute to Stupidity: The Robert Scott Anderson Archive (currently offline)
John Hansen - Slightly Insane Bounty Hunter - ASVS Vets' Assoc. Class of 2000
HAB Cryptanalyst | WG - Intergalactic Alliance and Spoof Author | BotM | Cybertron | SCEF
User avatar
Beowulf
The Patrician
Posts: 10621
Joined: 2002-07-04 01:18am
Location: 32ULV

Post by Beowulf »

Crayz9000 wrote:It's called a DOS batch script, look it up. And the syntax that goes with it is HORRIBLY limited.
I should go to bed soonish, but there's a reason why I recommended Perl for this task. It's designed to make this sort of thing easy.
"preemptive killing of cops might not be such a bad idea from a personal saftey[sic] standpoint..." --Keevan Colton
"There's a word for bias you can't see: Yours." -- William Saletan
User avatar
StimNeuro
Padawan Learner
Posts: 444
Joined: 2002-11-11 02:58pm
Location: Marietta, GA

Post by StimNeuro »

Thanks Crayz. I googled that term and found alot more useful sites.
"Well, it's too bad that thread pilots aren't allow to carry pistols.
Otherwise they would have stopped you." - Pablo Sanchez
User avatar
StimNeuro
Padawan Learner
Posts: 444
Joined: 2002-11-11 02:58pm
Location: Marietta, GA

Post by StimNeuro »

Problem finished without having to resort to using batch scripts. Simply sent the list of files to a text file, using dir/b, then added 'rename' in front of them and added the new name of the files with the Replace command. I knew about the /w, and /p switches, but never knew about the /b... How many bloody switches does that simple command have? :)
"Well, it's too bad that thread pilots aren't allow to carry pistols.
Otherwise they would have stopped you." - Pablo Sanchez
User avatar
Crayz9000
Sith Apprentice
Posts: 7329
Joined: 2002-07-03 06:39pm
Location: Improbably superpositioned
Contact:

Post by Crayz9000 »

StimNeuro wrote:Problem finished without having to resort to using batch scripts. Simply sent the list of files to a text file, using dir/b, then added 'rename' in front of them and added the new name of the files with the Replace command. I knew about the /w, and /p switches, but never knew about the /b... How many bloody switches does that simple command have? :)
dir /h

I think.
A Tribute to Stupidity: The Robert Scott Anderson Archive (currently offline)
John Hansen - Slightly Insane Bounty Hunter - ASVS Vets' Assoc. Class of 2000
HAB Cryptanalyst | WG - Intergalactic Alliance and Spoof Author | BotM | Cybertron | SCEF
User avatar
StimNeuro
Padawan Learner
Posts: 444
Joined: 2002-11-11 02:58pm
Location: Marietta, GA

Post by StimNeuro »

Heh, just started going through through the alphabet..

Valid: /a, /b, /c, /d, /l, /n, /o, /p, /q, /s, /t, /w, /x.

Note: Try /s. I thnk it does a dir on every folder on your drive.. or something. Either way, it goes on for almost a minute, switching directories on its own.


Why in the world do they have so many switches? Surely they have to have a purpose...
"Well, it's too bad that thread pilots aren't allow to carry pistols.
Otherwise they would have stopped you." - Pablo Sanchez
User avatar
Crayz9000
Sith Apprentice
Posts: 7329
Joined: 2002-07-03 06:39pm
Location: Improbably superpositioned
Contact:

Post by Crayz9000 »

You would have thought that Microsoft would have realized the utility of a MAN command years ago. But noooo....

Anyway, I have an old DOS 3.0 book in one of my bookshelfs. I'll have to drag it out and have a look.
A Tribute to Stupidity: The Robert Scott Anderson Archive (currently offline)
John Hansen - Slightly Insane Bounty Hunter - ASVS Vets' Assoc. Class of 2000
HAB Cryptanalyst | WG - Intergalactic Alliance and Spoof Author | BotM | Cybertron | SCEF
User avatar
Xon
Sith Acolyte
Posts: 6206
Joined: 2002-07-16 06:12am
Location: Western Australia

Post by Xon »

StimNeuro wrote:How many bloody switches does that simple command have? :)
Shit loads

"dir /?" is a good starting point.

Infact for any microsoft command line application, "/?" is a good switch to try first.
DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N]
[/O[[:]sortorder]] [/P] [/Q] [/S] [/T[[:]timefield]] [/W] [/X] [/4]

[drive:][path][filename]
Specifies drive, directory, and/or files to list.

/A Displays files with specified attributes.
attributes D Directories R Read-only files
H Hidden files A Files ready for archiving
S System files - Prefix meaning not
/B Uses bare format (no heading information or summary).
/C Display the thousand separator in file sizes. This is the
default. Use /-C to disable display of separator.
/D Same as wide but files are list sorted by column.
/L Uses lowercase.
/N New long list format where filenames are on the far right.
/O List by files in sorted order.
sortorder N By name (alphabetic) S By size (smallest first)
E By extension (alphabetic) D By date/time (oldest first)
G Group directories first - Prefix to reverse order
/P Pauses after each screenful of information.
/Q Display the owner of the file.
/S Displays files in specified directory and all subdirectories.
/T Controls which time field displayed or used for sorting
timefield C Creation
A Last Access
W Last Written
/W Uses wide list format.
/X This displays the short names generated for non-8dot3 file
names. The format is that of /N with the short name inserted
before the long name. If no short name is present, blanks are
displayed in its place.
/4 Displays four-digit years

Switches may be preset in the DIRCMD environment variable. Override
preset switches by prefixing any switch with - (hyphen)--for example, /-W.
copy & paste is so handy.
"Okay, I'll have the truth with a side order of clarity." ~ Dr. Daniel Jackson.
"Reality has a well-known liberal bias." ~ Stephen Colbert
"One Drive, One Partition, the One True Path" ~ ars technica forums - warrens - on hhd partitioning schemes.
User avatar
phongn
Rebel Leader
Posts: 18487
Joined: 2002-07-03 11:11pm

Post by phongn »

Crayz9000 wrote:You would have thought that Microsoft would have realized the utility of a MAN command years ago. But noooo....
Try "help dir," it's the rought equivilant to MAN for built-in commands.
User avatar
phongn
Rebel Leader
Posts: 18487
Joined: 2002-07-03 11:11pm

Post by phongn »

This site seems to have a bunch of useful links. Be aware that the NT command interpreter (CMD.exe) is more powerful than the old DOS one (command.com). If you've got NT, use the former, not the latter.
Post Reply