How To Make An Alphabetical List

Command Prompt


When I get a post published on Dave’s Computer Tips I like to save a copy in .mhtml format.

MHTML, short for MIME HTML, is a web page archive format used to combine in a single document the HTML code and its companion resources that are otherwise represented by external links (such as images, Flash animations, Java applets, and audio files).” ~ Wikipedia

I save from the Opera browser (older version). I’m not sure if the newer version has this option. To do this in Opera, go into Menu, then Page, and then Save as…

I was going to make a folder listing of all my articles in alphabetical order. I just wanted a printed list so I don’t accidentally upload the same article twice. Windows doesn’t have any options for doing this except through Registry hacking, third-party programs, or the Command Prompt.

Command Prompt

I’m going to show how to do it with the Command Prompt, but first I’m going to try to explain how to use the Command Prompt, concentrating now on basic navigation.

Commands and Switches

The folder path I want to go to is: C:\Downloads\docstosave\upload to Dave\posts and then I want to create a list of the folders’ contents in alphabetical order, which I then want to print.

Navigating to a folder

So first, let’s open up the Command Prompt by typing cmd in the search bar and then right-click on it and click on Run as administrator. What will open up is a small black window with white lettering on the inside. Mine is purple, my favourite colour.


Bonus Tip – Colors

You can click on the little dark square with the white C inside top left-hand corner and then click on Properties – this will give you some customization options. I just clicked on the Colors tab and then Screen Text then clicked on the white square in the color band. Then do the same for the Screen Background. Then OK. You can fool around with the other settings if you want.

command-prompt-properties

change-the-colour-options

My Command Prompt automatically opens with the path C:\Users\Terry.

There is a download folder within my profile folder at c:\users\Terry\downloads and if I wanted to move to that folder I would type the command (hit enter after every command):

cd downloads

But because I never use this folder, it’s empty, so I need to navigate to my main download folder which is at the root folder C: (you can look at your hard drive as one big folder with all the other folders and files nested in it). So I need to switch to C:\downloads


so I type: cd c:\downloads

Notice the difference. If I switch from one folder to the next a slash (\) is needed, but to switch to a sub-folder (one inside the other), I don’t use the slash (\). So now I have switched from C:\users\Terry to C:\downloads

Now I need to move forward to docstosave so I use the command: cd docstosave

There is no slash this time. So I repeat for the folder upload to dave and posts

cd upload to dave
cd posts

command-cd-post

I’m now where I want to be. But what if I wanted to go back…let’s say I wanted to backtrack to docstosave

I just type: cd..

That’s cd followed by two periods. Press enter. That moves me from posts to upload to dave. And then I’ll do it again until the prompt says C:\Downloads\docstosave\. I can go right back to the C: prompt.

Editor’s Note: Normally, there is not a Downloads directory on the C: Drive. This would have to be created first in order for this to work. The same goes for the other directories Terry is talking about here.

But I’m at the posts folder and this is where I will get my listing. I simply type: dir and hit Enter

command-dir

I have a listing of all items in that folder. But it’s messy with a lot of unwanted information. I can use a little more complicated command to clean up this list as I want it, by adding other switches to the basic dir command. I can find out what switches are available by typing: dir /?

command-dir-options

The /? at the end of any command will provide more help on what it does and how to properly format it.

In my case, I want a bare minimum of information – only the titles, so that implies the (/b) switch. I also want to create an ordered list so I will use the (/o) switch. But the /o switch has some sub-options; (n) by name, (e) by extension, (s) by size and so on. I want N By name (alphabetic).

So my command is going to look like this:

dir /b /on

One problem, this still just displays the information in this little window and I want it in a text file. So I have to use a switch not listed here. The greater than sign, from a math perspective (>). So now my command looks like this:

dir /b /on >

Now I need one more thing. I need to specify a file to send this data to, so I will just use a simple text file name of dir.txt

Here’s the final command that sends a list of a folder’s contents to a text file called dir.txt:

dir /b /on > dir.txt

Note: This will create a text file in the folder in question, posts in my case, and if it already exits it will be overwritten without warning!

If you want to add information to a file which already exists, use the following command, noting the two greater than signs (>>):

dir /b /on >> dir.txt

More Command Prompt Commands

Of course, the Command Prompt can be used for more than just listing folder contents:

    • bcedit and bootcfg
        – can be used to alter/fix the master boot record
    • chkdsk
        – can be used to scan and repair the hard drive
    • copy and xcopy
        – to copy files from one destination to another
    • diskpart
        – to manage partitions
    • format
        – to format disks
    • ipconfig
        – to manage network connections
    • start

– almost any program can be started from the Command Prompt

Here’s a more complete list at Lifewire. You can also see a complete list in the Command Prompt by typing help and hitting the Enter key.

Remember, putting a /? at the end of any of these commands will give you more information and what switches you can use to customize to your satisfaction. And there is the almost friendly Internet if you need more information. 😉

Instead of going through each folder individually, I could have used the following command to switch from C:\users\Terry to c:\downloads, but sometimes taking the long way is how you learn how things work.

cd c:\downloads\docstosave\upload to dave\posts

Posted in:
About the Author

Terry Hollett

Terry is a self-taught computer aficionado, who after being exposed to Windows 3.1 in the early 1990's devoured every book and magazine on the subject he could get his hands on. A published author with over 20 years' experience building and servicing computers for friends and family he started his first website in 2002 at Hit Any Key.

There are 2 comments

Your email address will not be published. Required fields are marked *