Go Back   SitePoint Forums > Forum Index > Program Your Site > General Development Issues
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Feb 4, 2005, 11:22   #1
ArticleBot
SitePoint Articles
 
ArticleBot's Avatar
 
Join Date: Apr 2001
Posts: 0
Article Discussion

This is an article discussion thread for discussing the SitePoint article, "Kev's Command Prompt Cheat Sheet"
ArticleBot is offline   Reply With Quote
Old May 11, 2005, 15:19   #2
MikeFoster
I'll take mine raw
 
MikeFoster's Avatar
 
Join Date: Dec 2002
Location: Alabama, USA
Posts: 2,561
Ah, a blast from the past! Oh we were great command-line warriors at one time

Want to run a program on every file in a directory?
This passes the file name (minus the extension) of every .xcp file (in the "cwd") to a program called xc:
Code:
@for %%f in (*.xcp) do xc %%~nf
btw... cwd == current working directory

Want to have more control over your directory listing?
This outputs a "bare" listing sorted ("ordered") by name:
Code:
dir /b /on
Want that directory listing sent to a file?
Code:
dir /b /on > dir_list.txt
Here's something you can't do easily from Windows Explorer.
Let's say we have a directory of files named like this:
beach001.jpg, beach002.jpg, beach003.jpg, beach004.jpg, etc.
Now we realise those weren't beach pics at all! We want to replace "beach" with "work" for all those files...
Code:
ren beach???.jpg work???.jpg
Pretty cool, eh? But you say some of those pics were gif files and not jpg files? No prob...
Code:
ren beach???.* work???.*
Let's create a network share called "shared_src" on a computer named "main_server":
Code:
net share shared_src=c:\public\src
Now on a different computer (on the network) lets map x drive to that share:
Code:
net use x: \\main_server\shared_src
Let's compare two different directory structures and save any differences in a file:
Code:
c:
cd \projects\old
dir /on /s > ..\old.txt
cd \projects\new
dir /on /s > ..\new.txt
cd ..
fc new.txt old.txt > project_comparison.txt
Ah, those were the days

Disclaimer - It's been a long time since I used some of these. Note that you can screw things up with some of these commands.
MikeFoster is offline   Reply With Quote
Old May 15, 2005, 16:42   #3
mark_W
SitePoint Wizard
 
mark_W's Avatar
 
Join Date: Mar 2004
Location: West Midlands, United Kingdom
Posts: 2,771
Quote:
Originally Posted by MikeFoster
Ah, a blast from the past! Oh we were great command-line warriors at one time

Want to run a program on every file in a directory?
This passes the file name (minus the extension) of every .xcp file (in the "cwd") to a program called xc:
Code:
 @for %%f in (*.xcp) do xc %%~nf
btw... cwd == current working directory

Want to have more control over your directory listing?
This outputs a "bare" listing sorted ("ordered") by name:
Code:
 dir /b /on
Want that directory listing sent to a file?
Code:
 dir /b /on > dir_list.txt
Here's something you can't do easily from Windows Explorer.
Let's say we have a directory of files named like this:
beach001.jpg, beach002.jpg, beach003.jpg, beach004.jpg, etc.
Now we realise those weren't beach pics at all! We want to replace "beach" with "work" for all those files...
Code:
 ren beach???.jpg work???.jpg
Pretty cool, eh? But you say some of those pics were gif files and not jpg files? No prob...
Code:
 ren beach???.* work???.*
Let's create a network share called "shared_src" on a computer named "main_server":
Code:
 net share shared_src=c:\public\src
Now on a different computer (on the network) lets map x drive to that share:
Code:
 net use x: \\main_server\shared_src
Let's compare two different directory structures and save any differences in a file:
Code:
 c:
 cd \projects\old
 dir /on /s > ..\old.txt
 cd \projects\new
 dir /on /s > ..\new.txt
 cd ..
 fc new.txt old.txt > project_comparison.txt
Ah, those were the days

Disclaimer - It's been a long time since I used some of these. Note that you can screw things up with some of these commands.
Some of those are awesome!
mark_W is offline   Reply With Quote
Old May 14, 2005, 22:29   #4
geekpipe
SitePoint Zealot
 
geekpipe's Avatar
 
Join Date: Jun 2003
Location: ny
Posts: 132
heh this brings back memories...
geekpipe is offline   Reply With Quote
Old May 15, 2005, 21:13   #5
MikeFoster
I'll take mine raw
 
MikeFoster's Avatar
 
Join Date: Dec 2002
Location: Alabama, USA
Posts: 2,561
Thanks

The Command Prompt (I still call it a "DOS Box" ) can be very useful - I use it often. One problem with opening a Command Prompt from the "Start" menu is that, after opening it you then have to "cd" (change directory) to the directory where you need to work. Here's something I did to help. The following creates a new action for the "Folder" file type. After doing this you can right-click on a folder (in the "Folders" view of Explorer) and select "Command Prompt" and it will open it with the "CWD" (current working directory) set to the folder you right-clicked on.

On the main menu bar of Explorer (not 'Internet' Explorer) click "Tools", then "Folder Options...", then the "File Types" Tab. Now you see a list of file types. Look for one named "Folder". There is also one named "File Folder" - don't select that one, select the one named "Folder" (I have Windows XP Pro so things may be different for you now, depending on what version of Windows you have). Click the "Advanced" button. Now you get a dialog box named "Edit File Type" - it has a list of "Actions" (you'll probably see the "explore" and "open" actions already there). Click the "New..." button. Now you get a dialog box named "New Action" which has two text fields. For "Action" I used this: Command Prompt. For "Application used to perform action" I used this: C:\WINDOWS\system32\cmd.exe "%1". Click the "OK" buttons for all dialog boxes you opened.

This has been very useful to me. I hope it is useful to you
MikeFoster is offline   Reply With Quote
Old May 16, 2005, 00:06   #6
dc dalton
SitePoint Wizard
 
dc dalton's Avatar
 
Join Date: Nov 2004
Location: Right behind you, watching, always watching.
Posts: 5,940
damn I DO miss the days of the dos prompt even though I still use it a lot. I think thats why I enjoy the console on my servers so much ...... and the wonderful thing is? It ONLY does what you tell it to do (unlike some "other" apps we wont mention)

nice article ...... made me feel "homesick" for the good old days!
dc dalton is offline   Reply With Quote
Old Mar 30, 2008, 07:21   #7
tauperkin
SitePoint Addict
 
tauperkin's Avatar
 
Join Date: Jun 2006
Posts: 222
Oh my gosh!

I absolutely LOVE DOS command prompts. I think I learned every single one. Then it all went to Windows.

It's so funny...this article says it's a "mysterous utility." That's funny because it was the way you did things before it all went to these pretty little folders and such.
tauperkin is offline   Reply With Quote
Old Jul 29, 2008, 04:30   #8
FredJones53
SitePoint Member
 
Join Date: Jul 2008
Location: UK
Posts: 17
Bah, get a real command line like bash or zsh
FredJones53 is offline   Reply With Quote
Old Oct 28, 2008, 17:45   #9
hobbit.debian
SitePoint Member
 
Join Date: Oct 2008
Posts: 1
how do you run a command (like net or something with a lot of sub commands) and have it appear in the prompt? i figured it out once but i forgot.
should look something like this if you do it correctly:
C:\WINDOWS\System32>net>
then you can type net start,config,etc. but without the net part. also might be like:
C:\WINDOWS\System32\net.exe>
thanks
hobbit.debian is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 06:19.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved