Previous section   Next section

FILE-MANAGEMENT COMMANDS

The file-management commands and procedures allow a user to create, remove, copy, move, and rename files and directories. These tasks may be completed using graphical methods in Windows Server 2003 Explorer or My Computer windows. My Network Places windows will permit some of these actions for resources shared across the network, provided that the user has the permission to execute them. Explorer is the application we use for most examples.

Displaying Path Names

While in Windows Server 2003 Explorer, a user can view the full path name of her current location by selecting View from the menu bar and then selecting Options View. In the View tab, select the option Display the full path in the title bar, which is the default setting.

If you want to determine the current directory while at the command prompt, type cd and press ENTER.

Creating and Removing Folders

Windows Server 2003 provides command-line and graphical procedures for creating and removing directories or folders. This section discusses both.

CREATING FOLDERS

New folders can be created through Windows Server 2003 Explorer and My Computer windows using the same procedure. To create a folder (or directory) from Windows Explorer, follow this procedure:

  1. Select the folder that will contain the new directory.

  2. Select File from the menu bar.

  3. Select New.

  4. Select Folder.

  5. In the Contents of pane, the New Folder icon will appear at the bottom of the file list. Enter the name of the new folder.

MKDIR COMMAND

The mkdir command enables the user to create a directory from the command line. Another name for it is md, and its syntax is

mkdir directory-name

or

md directory-name

The directory-name parameter is the name of the folder (or directory) you wish to create. The drive designation may be included here as well as a path should you wish to create a subdirectory. Suppose, for example, that the current directory is the root directory on the C: drive and you want to create the folder budget in the year2002 directory on the D: drive. To do this without moving from the current location, enter

mkdir d:\year2002\budget
REMOVING FOLDERS

Windows Server 2003 provides several ways to remove folders through Explorer or My Computer. Removing a folder places it in the Recycle Bin where it can still be accessed. Only when the Recycle Bin is cleared are folders permanently removed from the system.

The simplest way to remove a folder is to select it and then click Delete. A confirmation message similar to the following will display: "Are you sure you want to remove the folder and move all its contents to the Recycle Bin?" to which you must respond by clicking Yes or No.

Another way to remove a folder using Windows Server 2003 Explorer is:

  1. Select the folder.

  2. Select File from the menu bar.

  3. Click Delete.

Step 2 is not necessary if you select the folder by right-clicking it. Doing so displays a menu that also contains the Delete option.

As an alternative, you can select the folder and then, while holding down the left mouse button, drag the folder to the Recycle Bin icon and release the button. If you want the folder to be permanently removed from the system, hold down the SHIFT key while dragging the folder to the Recycle Bin.

rmdir Command

The rmdir command, also known as rd, deletes the given directory (or folder). The syntax is

rmdir directory-name [/s]

or

rd directory-name [/s]

The directory-name parameter is the name of the directory or folder you wish to delete. It can contain both the drive designation and the path name if necessary.

The /s switch is optional and enables any files and subdirectories in the folder to be deleted as well. If it is not used, the directory must be empty before it can be removed.

Moving between Folders

Moving between folders in Windows Server 2003 is as simple as selecting a different folder with the mouse, which you can do in Explorer either in the All Folders or the Contents of pane. Within My Computer windows, just click the icon that represents the folder or the folder name.

CHDIR COMMAND

The chdir command, also known as cd, enables the user to display the name of the current directory as well as to change to a different directory. The syntax is

chdir [/d] [[drive:]directory-name]

or

cd [/d] [[drive:]directory-name]

The parameters /d and drive:directory-name are optional. If neither is entered, the chdir command will display the name of the current directory, including the drive designation.

The /d switch changes the current drive designation. The drive:directory-name parameter identifies the new drive and directory. The drive designation is entered only when necessary. Using a double period (..) in place of the directory name will change the directory from the current one to its parent.

Creating and Removing Files

This section provides procedures and commands for creating and removing files within Windows Server 2003.

CREATING FILES

Files are usually created in Windows Server 2003 via an installed application such as Notepad or WordPad. From within Windows Server 2003 Explorer and the My Computer windows, selecting File New will provide a list of the file types you can create based on the applications installed on your system. In addition, the MS-DOS editor, edlin, is accessible from the command prompt.

REMOVING FILES

The procedure for removing files is the same as that for removing folders. The simplest method is to select it and then click Delete. To do so using Windows Server 2003 Explorer:

  1. Select the file.

  2. Select File from the menu bar.

  3. Click Delete.

Step 2 is not necessary if you select the file using the right mouse button. Right-clicking will display a menu that also contains the Delete option.

As an alternative, you can select the file and drag it to the Recycle Bin icon. If you want the file permanently removed from the system, hold the SHIFT key down while dragging it to the Recycle Bin or simultaneously press the SHIFT and DELETE keys.

To select multiple files for deletion, hold down the CRTL key while selecting the files with the mouse and then drag them to the Recycle Bin.

DEL AND ERASE COMMANDS

The del command deletes or erases files from the system. Another name for this command is erase, and its syntax is

del file(s) [options]

or

erase file(s) [options]

Table A.34. del Command Options

Option

Qualifier

Description

/a

:attributes

Deletes files that match the given attributes: r for Read-Only, h for Hidden, s for System, a for Archive. A minus (–) sign may be used in front of any of the above options to identify files that do not match the given attribute.

/f

 

Forces Read-Only files to be deleted.

/p

 

Requires the user to confirm whether a file should or should not be deleted by displaying the following prompt: file, Delete (Y/N)? Y will delete the file, N will not. (To abort the delete command altogether, enter a CTRL+C.)

/q

 

Does not prompt for confirmation. This is the default option.

/s

 

Deletes the files listed not only from the current directory but also from the subdirectories.

The file(s) parameter identifies the files to be removed from the system and can contain the drive designation and the directory path in the format drive:path\file. More than one file can be deleted using one del command by separating the multiple file names with spaces, commas, or semicolons.

The wildcard characters * and ? can be used when specifying files to be deleted. It is important that these be used with care to reduce the risk of deleting critical files. See Table A.34 for options.

Copying and Moving Files

The copy procedure creates a duplicate of the original file in another location so that more than one copy exists. The move procedure places the original file in another location without making a duplicate of it.

Windows Server 2003 provides both graphical and command-line methods for copying and moving files. The graphical method using the Explorer application provides the user multiple ways to copy and move, such as menus and drag and drop. In addition, it enables a user to copy and move files within and between disks, or across the network.

The following sections discuss both the graphical and command-line procedures for these tasks.

COPYING FILES

To copy a file using the drag-and-drop method in Windows Server 2003 Explorer:

  1. Display the file in the Contents of pane.

  2. Make sure that the destination directory is visible in the All Folders pane. (Or start another copy of Explorer and display the destination directory in the Contents of pane.)

  3. Select the file you wish to copy.

  4. Hold down the CTRL key and drag the file to its destination.

For multiple files, in step 3, hold down the CTRL key while selecting.

To use the menu bar in Explorer to copy files:

  1. Select the files.

  2. Select Edit Copy or press CTRL+C.

  3. Select the destination directory.

  4. Select Edit Paste or press CTRL+V.

Selecting the files with the right mouse button also displays a menu that contains the copy command.

Copying an executable file (one that has a .exe or .com extension) may create a shortcut—that is, a link to the executable that gives the user an alternative way of executing the program. Shortcuts are often dragged and dropped to the main screen so that the user can bypass the menus.

COPY COMMAND

The copy command copies the source file or files to the indicated destination. It can also be used to combine the contents of files. The syntax is

copy [/a|/b] source-file [/a|/b] dest-file [/a|/b] [options]

The sourcefile is the name of the file to be copied. It can be just the file name, it can include the drive designation and the directory path as necessary, or it can be an actual device.

The dest-file is the name of the destination file but can be extended to include the drive designation and the directory path, or it can be a device name such as COM1 or LPT1. If this parameter is omitted, a file with the same name, creation date, and time is created in the current directory and on the current drive. If a file with that name already exists, an error is displayed.

The parameter [/a|/b] indicates whether the file is ASCII (/a switch) or binary (/b switch). The default value is binary when copying and ASCII when combining. When the [/a|/b] switch is entered before the name of the source file, all items that follow use that flag until a different [/a|/b] switch is entered. This new switch applies to the source file that immediately precedes it as well as to any source files that follow it. Placement of the /a or /b after the source file or the destination file results in different copy procedures, as explained in Table A.35.

Table A.35. copy Options

Option

Used after the source-file

Used after the dest-file

/a

Copies all data in the file up to the first end-of-file character. The end-of-file character is not copied. The data is considered to be in ASCII format.

Adds an end-of-file character to the end of the dest-file as the last character.

/b

Copies all data in the file including the end-of-file character. The data is considered to be in binary format.

Does not add an end-of-file character to the end of the dest-file.

When the dest-file is a device, the /b switch should be used so that special control characters are copied to it as data. If the /a switch is used in this instance, the ASCII copy might cause those control characters to be interpreted, providing unpredictable results.

Four additional options are available, indicated in the syntax line as options, and defined in Table A.36.

copy Command Examples

To copy the file Budget.xls, which exists on the C: drive, to the directory d:\financial\year2000, enter the following:

copy budget.xls d:\financial\year2000

Table A.36. copy Command Options

Option

Description

/n

Uses the MS-DOS file name format of filename.ext when copying files with longer names.

/v

Verifies each file copied. If an error occurs, a message is displayed. This switch causes the copy command to execute more slowly.

/y

Suppresses the prompt to overwrite an existing file.

/z

Copies networked files so that they are in restart mode.

If you want to copy an ASCII file up to the first end-of-file character and output it to a file with the end-of-file character added, enter

copy demo.txt /a newdemo.txt /a
COMBINING FILES WITH THE COPY COMMAND

To instruct the copy command to combine files, enter multiple source files separated by plus signs. Remember that the default file type is considered ASCII when combining files. For binary files, you must enter the /b switch. The syntax for combining files is

copy [/a|/b] source-file1 [+ source-file2 [/a|/b] [+ source-file...]]
dest-file [/a|/b] options

Wildcard characters can also be used to designate multiple files to be combined.

A special use of the plus sign parameter allows the user to update the date and time of the file to the current date and time without changing the file's contents. The syntax is

copy [/a|/b] source-file+ ,,
COPY COMMAND EXAMPLES USING THE COMBINING OPTION

Suppose that a department manager wants to combine all of her employees' monthly status reports for April into one file. She enters

copy grwapr.rpt + ebgapr.rpt + eegapr.rpt April.rpt

If all of the above files were in the same directory, a variation of this command could be entered:

copy *apr.rpt April.rpt
XCOPY COMMAND

The xcopy command is more comprehensive than the copy command; it allows the user to copy not only files and directories but also subdirectories. The syntax is

xcopy source-file [dest-file]
[options]

The source-file parameter represents the names of the files to be copied and their locations. It must include either a drive designation or a directory path.

The dest-file parameter is the destination of the files to be copied and may include the file name as well as the drive designation and the directory path as necessary. Specifying the dest-file is optional, and if it's not included, the source files are copied to the current drive and directory. The destination files automatically have the archive attribute set.

xcopy Command Example

To copy the directory budget and all of its files and subdirectories to the year2000 directory, creating a directory named budget at the same time, enter

xcopy \budget \year2000 /i/s/e

The /i switch will create a directory named budget under this directory, copying both files and subdirectories; the /e switch will ensure that empty subdirectories get copied as well. See Table A.37 for options.

MOVING FILES

To move a file using the drag-and-drop method in Windows Server 2003 Explorer:

  1. Display the file in the Contents of pane.

  2. Make sure that the destination directory is visible in the All Folders pane. (Or start another copy of Explorer and display the destination directory in the Contents of pane.)

  3. Select the file you wish to move.

  4. Drag the file to its new destination if it is on the same disk as its current location. Otherwise, hold down the SHIFT key while dragging the file to force the move. If the SHIFT key is not held down, the file will be copied, not moved.

Remember, to select multiple files, hold down the CTRL key while selecting. To use the menu bar in Windows Server 2003 Explorer to do this:

  1. Select the files.

  2. Select Edit Cut or press CTRL+X.

  3. Select the destination directory.

  4. Select Edit Paste or press CTRL+V.

move Command

The move command actually moves files from one directory to another so that they no longer exist in their original location. The syntax is

move source-file(s) dest-file

The source-file(s) parameter indicates the files that you wish to move. It can be just the file name or it can include the drive designation and directory as necessary. Wildcard characters can be used to move multiple files.

Table A.37. xcopy Command Options

Option

Qualifier

Description

/a

 

Copies only those source-files with the Archive attribute set. Using this switch does not cause the Archive attribute to change.

/d

:date

Copies only those files with a modification date the same as or after the :date qualifier, which is in the format of MM-DD-YY. The :date qualifier is optional; if it is not used, only those files that are more recent than any existing destination files are copied.

/e

 

Must be used with the /s and /t options and allows empty subdirectories to be copied as well as those containing files.

/exclude

:filename

Excludes from copying the files contained in filename. Filename is a file that can contain one pattern per line without the use of wildcard characters. A file is not copied when any portion of the source-file parameter matches a line in filename.

/i

 

Creates a directory called dest-file, if the source-file contains wildcards or if the source-file is a directory and if dest-file does not exist. Then copies all source-files to the dest-file directory. When not set, the xcopy command prompts the user to identify the dest-file as a file (F) or a directory (D).

/k

 

Copies the source-files without changing the Read-Only attribute. Automatically removes the Read-Only attribute whenever this option is not used.

/n

 

Copies files using the short file name format of filename.ext. This is required when copying files to a system that can only handle shorter file names.

/p

 

Displays a confirmation prompt prior to creating the destination file.

/q

 

Does not display messages.

/r

 

Enables the command to copy over read-only files.

/s

 

Copies both directories and subdirectories, except empty ones. When omitted, subdirectories are not copied.

/t

 

Does not copy files under subdirectories but only the subdirectories themselves. Must be used with the /e switch to copy empty subdirectories.

/u

 

The update option. When used, it will copy only files that already exist at the destination, thereby updating them.

/v

 

Verifies each new file.

/w

 

Displays a message that requires the user to press any key to start the copy process.

/x

 

Copies file auditing settings.

/y /-y

 

Suppresses prompting before overwriting a file; -y forces the prompt.

/z

 

Copies files over the network in restartable mode.

The dest-file parameter represents the new location. It too can be a new file name or it can include a new drive designation or new directory path as necessary. Wildcard characters can be used here as well, such as when you need to change the extensions on a number of file names.

RENAMING FILES OR FOLDERS

To rename a file using Windows Server 2003 Explorer:

  1. Select the file or folder.

  2. From the menu bar select File Rename.

  3. Enter the new name for the file or folder.

or

  1. Select the file or folder by right-clicking to display a menu.

  2. Select Rename.

  3. Enter the new name for the file or folder.

RENAME COMMAND

The rename, or ren, command permits changing the name of a file or directory without changing its location. In other words, file names cannot be changed across drives or directories with this command. For that, you need the copy or move command. The syntax for both formats of rename is

rename oldfile newfile

or

ren oldfile newfile

The oldfile parameter is the name of the file you wish to change and may include the drive designation and directory path. The newfile parameter is the new name for the file and may not include a drive or path. If a file already exists with the new file name, an error will be displayed. Wildcard characters can be used in names of both old files and new files.

Determining File Type

Windows Server 2003 Explorer will automatically attempt to identify a file type, which is displayed in the Type column of the Contents of pane as long as a detailed view is selected (View Details). Another method of displaying the file type is to select File Properties General. You can also select the file with the right mouse button and then select Properties General.


  Previous section   Next section
Top