Recipe 8.10. Copying, Moving, or Renaming a File or Folder


Problem

You want to copy or move a set of files or folders to another location on the file system or to another computer.

Solution

Using a graphical user interface

  1. Open Windows Explorer.

  2. In the left pane, browse to the parent folder of the file or folder you want to copy, move, or rename.

  3. In the right pane, right-click the file or folder.

  4. To rename, select Rename, enter the new name, and hit Enter.

  5. To move or copy, select Cut or Copy, respectively. Browse to the new location, right-click in the folder, and select Paste.

Using a command-line interface

Moving, copying, and renaming files is pretty straightforward from the command line:

> move <Source> <Destination> > copy <Source> <Destination> > ren <Source> <Destination>

Using downloadable software

PowerDesk Pro from VCOM (http://www.v-com.com/product/PowerDesk_Pro_Home.html) has extensive file management and organization features in an easy to use interface. You can use PowerDesk Pro to completely replace Windows Explorer. In addition to the standard edit, move, delete, and search features, PowerDesk Pro comes with an FTP Manager, Sync Manager (for comparing and syncing two folders), Size Manager (for monitoring drive space), and Archive Manager (for compressing and expanding files).

You can download a trial version of PowerDesk Pro called PowerDesk Express for free. You can purchase PowerDesk Pro for $49.99.

Using VBScript
' This code shows how to rename (same as move in WMI) and copy a file ' or folder.  ' ------ SCRIPT CONFIGURATION ------ strComputer = "." strCurrentFile = "<CurrentFilePath>"  ' Path to existing file or folder strNewFile     = "<NewFilePath>"      ' New path of file or folder ' ------ END CONFIGURATION --------- set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set objFile = objWMI.Get("Cim_Datafile='" & strCurrentFile & "'") WScript.Echo "Renaming " & strCurrentFile & " to " & strNewFile intRC = objFile.Rename(strNewFile) if intRC <> 0 then    WScript.Echo "There was an error renaming the file: " & intRC else    WScript.Echo "File rename successful" end if ' ------ SCRIPT CONFIGURATION ------ strComputer = "." strCurrentFile = "<CurrentFilePath>" ' Path to existing file or folder strNewFile     = "<NewFilePath>"     ' Path to copy file or folder ' ------ END CONFIGURATION --------- set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set objFile = objWMI.Get("Cim_Datafile='" & strCurrentFile & "'") WScript.Echo "Copying " & strCurrentFile & " to " & strNewFile intRC = objFile.Copy(strNewFile) if intRC <> 0 then    WScript.Echo "There was an error copying the file: " & intRC else    WScript.Echo "File copy successful" end if



Windows XP Cookbook
Windows XP Cookbook (Cookbooks)
ISBN: 0596007256
EAN: 2147483647
Year: 2006
Pages: 408

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net