Programmer's Survival Guide for Windows

File System, CMD & Source-code Editors

Windows - Programmers Must Know

Show Filename Extension in File Explorer

In Windows, a file has two parts: name and extension (or type), separated by dot (.), e.g., "Hello.java", "in.txt". This is a legacy since the old DOS'es day of 8.3 (name.type) format.

In Windows' File Explorer, by default, "Hello.java" will be shown as "Name" of Hello" and "Type" of "JAVA File"; "in.txt" as Name of "in" and Type of "TXT File". It is annoying that the file extension is not shown together with file name.

To show the file extension, in Windows 11, choose "View" menu ⇒ "Show" ⇒ "File name extensions".

CMD

Retrieve history commands (Up/Dn). Auto-complete Filename (Tab). See below.

Keyboard Short-Cut

Ctrl-A, Ctrl-S, Ctrl-Z, Ctrl-C, Ctrl-V, Ctrl-X, etc. See below.

Windows' File System

DirectoryStructure.png

In Windows, files are organized in directories (aka folders). The directories are organized in a hierarchical tree structure, starting from the so-called root directory for EACH of the hard drive (as illustrated). A directory may contain sub-directories and files. A sub-directory may contain sub-sub-directories and files, and so on.

Windows' file system is organized in drives, identified by a drive letter followed by a colon, e.g., C:, D: and E:. Each drive has its own root directory, such as C:\, D:\ and E:\, where the "\" (back-slash) denote the root directory of each drive.

Windows' file system is NOT case-sensitive, a rose is a Rose, and is a ROSE.

Filename and File Type

A Windows' filename consists of two parts: filename and file type (or file extension) separated by a dot, e.g., Hello.java, Hello.class, Test.txt, etc. Windows can associate a program to each file type. For example, double-clicking a .txt invokes NotePad; double-clicking .jpg invokes Photo or Paint. This is a legacy from the old DOS'es day of 8.3 (name.type) filename syntax.

Show Filename Extension in Windows "File Explorer"

For programmers, it is important to SEE the file type inside the "File Explorer", which is hidden by default. For example, "Hello.java" is displayed as "Name" of "Hello" with the "Type" of "JAVA file".

To view the file type in "File Explorer" (Windows 11): choose "View" menu ⇒ "Show" ⇒ Check "File name extensions".

Drive-Letter, Pathname and Filename

To reference a file, you need to provide the drive letter, the directory name (aka pathname) and the filename. For example, in "C:\Program Files\java\jdk1.7.0_07\bin\javac.exe", the drive letter is C:, the pathname is "\Program Files\java\jdk1.7.0_07\bin\" and the filename is "javac.exe". The leading "\" (back-slash) denotes the root directory for that drive. The sub-directories are separated by "\" (back-slash).

The pathname (or directory name) can be specified in two ways:

  1. Absolute Pathname: An absolute pathname begins from the root directory of a drive. It starts with X:\ (where X denotes the drive letter and the leading "\" denotes the root), and contains all the sub-directories leading to the file separated by "\". For example, "C:\Program Files\java\jdk1.7.0_07\bin\".
  2. Relative Pathname: A relative pathname is relative to the so-called current drive and current working directory. For example, if the current drive and working directory is "C:\Program Files\java\", then the relative path "jdk1.7.0_07\bin\" resolves to "C:\Program Files\java\jdk1.7.0_07\bin\". Take note that a relative pathname does NOT begin with a "\" (back-slash).

Command Prompt "CMD"

Programmers use a Command-Line Interface (CLI) to issue text-commands to the Operating System (OS), instead of clicking on a Graphical User Interface (GUI). This is because command-line interface is much more powerful and flexible than the graphical user interface.

The CMD (Command Interpreter or Command Prompt) is a command-line Interface (aka shell). It supports a set of commands and utilities; and has its own programming language for writing batch files (or shell scripts).

You can launch a CMD via:

  1. "Search" ⇒ Type "cmd" ⇒ Enter; or
  2. "Start" button ⇒ "Run..." ⇒ Enter "cmd"; or
  3. "Start" button ⇒ All Programs ⇒ Accessories ⇒ Command Prompt.

The CMD displays a command-prompt which ends with a ">", in the form of "DriveLetter:\path\to\current-working-directory>", e.g., "C:\Users\ahhuat>". You can enter your command after the prompt.

Note: Windows has a newer and more powerful shell called "Power Shell", which will not be covered here.

Current Drive and Current Working Directory

Each CMD session maintains a so-called current drive and current working directory, which is shown in the prompt in the form of "drive:\path\to\current-directory>". All relative pathnames are relative to this current drive and current working directory.

Command: Set Current Drive (x:)

To set or change the current drive, enter the drive letter followed by a colon (:), e.g.,

prompt> d:    // Change the current drive to D. The prompt changes to D:\...
D:\...> c:    // Change the current drive to C. The prompt changes to C:\...
C:\...>

Take note that commands are NOT case-sensitive in CMD.

Command: Change Directory (cd)

To change current working directory under the current drive, use command "cd new-path" (change directory).

It is important to take note that you need to set the current drive first (via "x:" command) before setting the current directory under the current drive.

You can specify new-path in two ways: absolute or relative. An absolute path begins with a "\" or root directory. A relative path is relative to the current working directory and does NOT begin with a leading "\". For example,

prompt> c:
   // Set current drive to C. The prompt changes to C:\...
C:\....> cd \           
   // Set current directory to the root directory of the current drive
C:\> cd Windows
   // Set current directory to "Windows" relative to current directory of the current drive
C:\Windows> cd system
   // Set current directory to "system" relative to current directory of the current drive
C:\Windows\system> cd \myproject\java
   // Set current directory absolutely to "\myproject\java" of the current drive
C:\myproject\java> cd "\Program Files\java\jdk1.7.0_07\bin"
   // Set current directory absolutely. Enclosed with double quotes if pathname contains blank.
C:\Program Files\java\jdk1.7.0_07\bin> d:
   // Set the current drive to D drive
D:\....> cd \
   // Change directory to the root of the current drive
D:\> cd Java
   // Change directory to the "Java" sub-directory of the current directory
D:\Java>

Take note that:

  1. You need to set the current drive and current directory in two commands: X: and cd.
  2. The current drive and current working directory is displayed in the command prompt before the ">".
  3. The commands, pathnames, filenames are NOT case-sensitive.

You can cd in multiple stages (e.g., one cd for each sub-directory), or cd in one single stage with the full pathname.

prompt> c:                                  // C:\...
C:\....> cd \                               // C:\
C:\> cd Program Files                       // C:\Program Files
C:\Program Files> cd java                   // C:\Program Files\java
C:\Program Files\java> cd jdk1.7.0_07       // C:\Program Files\java\jdk1.7.0_07
C:\Program Files\java\jdk1.7.0_07> cd bin   // C:\Program Files\java\jdk1.7.0_07\bin
C:\Program Files\java\jdk1.7.0_07\bin>
 
// Same As
prompt> c:
C:\....> cd \Program Files\java\jdk1.7.0_07\bin
C:\Program Files\java\jdk1.7.0_07\bin>
Parent directory (..) and Current Directory (.)

You can use ".." (double-dot) to refer to the parent directory and "." (single-dot) to refer to current directory. For example,

C:\Program Files\java\jdk1.7.0_07\bin> cd ..   // Parent directory
C:\Program Files\java\jdk1.7.0_07> cd ..
C:\Program Files\java> cd ..
C:\Program Files>

Setting proper working directory is important. For example, to compile a Java program called "Hello.java" stored in "D:\myproject\java\":

  1. Set the working directory to "D:\myproject\java\", and reference the file relatively with filename only (without the path):
    prompt> d:
    D:\...> cd \myproject\java
    D:\myproject\java> javac Hello.java   // Filename only, in current directory
  2. You can also refer to a file with its full path in any working directory, but you will have a hard time looking for the output.
    // Any working directory
    prompt> javac d:\myproject\java\Hello.java

Command: List Directory (dir)

You can list the contents of the current directory via the dir command, for example,

prompt> dir              // List of contents of the current directory
......
prompt> dir Hello.java   // Show the file "Hello.java" only
Wildcards * and ? for Pattern Matching

You can use wildcards for pattern matching. The wildcard * matches zero or more (any) characters; ? matches one (any) character.

prompt> dir *.java  // List files ending with ".java"
.....
prompt> dir test*   // List files starting with "test"
.....
prompt> dir test?.txt   // List files such as "test9.txt"
.....

Windows Graphical Interface - File Explorer

You could, of course, view the contents of a directory (folder) using the Windows' "File Explorer" more conveniently. But,

  • View File Extensions: Windows' File Explorer, by default, will not show the file extensions. For example, "hello.txt" will be listed as "hello" with Type of "TXT File". To display the file extension (in Window 11), choose "View" menu ⇒ "Show" ⇒ Check "File name extensions". (For older version of Windows, goto "Control Panel" ⇒ File Explorer Option (or View Option) ⇒ View ⇒ Uncheck "Hide extensions for known file types".)
  • View Hidden Files: Windows' File Explorer, by default, will not display hidden files and directories (e.g., "C:\ProgramData"). To display the hidden items, choose "View" menu, check "Hidden Items".
Tips and Tricks for File Explorer
  1. You can click on the "folder name" on the menu bar to see the full pathname of the current folder.
  2. [TODO]

Shortcut Keys in CMD Shell - IMPORTANT

Command History (Up/Dn): You can use the up/down arrow keys to scroll through the previous/next command in the command history.

Filename Auto-Complete (Tab): Type the first few characters of a file/directory name, and press TAB key to auto-complete the file/directory name. Press TAB key repeatedly to cycle through all the matches.

Copy/Paste: In the latest CMD, you can use Ctrl-C/Ctrl-V for Copy/Paste.

(In earlier version, you need to "Enable Ctrl Key Shortcuts" via click on the CMD icon (top-left corner) ⇒ Properties ⇒ Options ⇒ Edit Options ⇒ Check "Enable Ctrl Key Shortcuts").

(In the earlier version of CMD, you need to enable Copy/Paste by clicking on the CMD icon (top-left corner) ⇒ Properties ⇒ Options ⇒ Edit Options ⇒ Check "QuickEdit Mode". Once enabled, you can right-click to copy the highlighted text, and another right-click to paste on the command-line.)

Moving the Command-Line Cursor: In CMD, you CANNOT use mouse pointer to move the command-line cursor. Instead, you need to use Left/Right-Arrow, Backspace or Delete keys to move the command-line cursor.

These are the various ways of moving the command-line cursor:

  • Left/Right Arrow Key: Move the cursor one character to the left/right.
  • Backspace/Delete Key: delete the previous/current character under the cursor.
  • ESC Key: Clear command-line.
  • Home/End Keys: Move to the begin/end of command line.
  • Ctrl + Left/Right-Arrow Key: Move one "word" to the left/right.

Tips and Tricks for CMD

  1. CMD is NOT case-sensitive.
  2. The screen buffer size (controlling the amount of messages retained in the screen) can be configured under "CMD icon" ⇒ "Properties" ⇒ "Layout". You should set to a bigger number (500-2000), so that you can view more old messages.
  3. You can also change the colors and font via "CMD icon" ⇒ "Properties" ⇒ "Colors" and "Properties" ⇒ "Font".
  4. [TODO]

Windows Tips and Tricks

Keyboard Shortcuts for Windows

Programmers use keyboard shortcuts instead of mouse to perform most of the editing tasks, such as positioning the cursor, selecting texts, copy and paste. Below are the frequently-used keyboard shortcuts for the programmers.

Keyboard Shortcut Function
Ctrl+C, Ctrl+V, Ctrl+X Copy, Paste, Cut
Ctrl+S Save
Ctrl+F Find
Ctrl+Z, Ctrl+Y Undo, Redo
Ctrl+RightArrow, Ctrl+LeftArrow Goto next/previous word
Home, End Goto begin/end of the current line
Ctrl+Home, Ctrl+End Goto top/end of document
Ctrl+A Select all
Ctrl+Shift+RightArrow, Ctrl+Shift+LeftArrow Select words
Shift+DownArrow, Shift+UpArrow Select lines
Shift+RightArrow, Shift+LeftArrow Select characters
Shift+End, Shift+Home Select till end/begin of current line
Alt+Tab Switch between open applications
Alt+F4 Close the current application
MORE...  

Mouse Clicks

  1. Single-click to position the mouse pointer.
  2. Double-click to select a word.
  3. Triple-click to select a paragraph.

Source-Code Editors and IDE

To learn a new programming language, you could begin with a graphical Source-Code Editor, with provides syntax highlighting. But you must switch over to an Integrated Development Environment (IDE), which provides a graphic debugger, when you are working on complex programs and projects to improve your productivity.

Read "Source-Code Editors and IDE".

Windows Default Text Editor "Notepad"

Notepad is a plain text editor, which does not support syntax highlighting. Do NOT use NotePad for programming. At a minimum, use NotePad++ to replace NotePad, and associate the text files (.txt, etc) to NotePad++, instead of NotePad.

Not sure if NotePad can be removed from Windows!

You should also have a programming text editor (such as sublime text or atom), and light-weight IDE (such as VS Code).

 

REFERENCES & RESOURCES

  1. Microsoft MS-DOS User's Guide and Reference.
  2. "Command-line Reference for IT Pros - Technical Reference", available under Windows "Help".