Moving Folders by Using the Shell Folder Object

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

The Shell method MoveHere is similar to the CopyHere method; the only difference is that MoveHere moves a folder from one location to another, whereas CopyHere copies the folder (resulting in two identical folders). Otherwise, MoveHere is called in the same manner as CopyHere and accepts the same set of optional parameters found in Table 11.9.

Scripting Steps

Listing 11.13 contains a script that moves a folder to a new location, displaying the Move Files dialog box as it carries out the procedure. To carry out this task, the script must perform the following steps:

  1. Create a constant named FOF_CREATEPROGRESSDLG and set the value to &H0&.
  2. Create a variable named TargetFolder and set the value to D:\Archive. This variable is used to indicate where the folder should be moved.
  3. Create an instance of the Shell object.
  4. Use the Namespace method to create a Folder object representing D:\Archive. This is done by passing the variable TargetFolder to the Namespace method. If the folder D:\Archive does not exist, the procedure fails.
  5. Use the MoveHere method to move C:\Scripts to D:\Archive. This creates a new folder, D:\Archive\Scripts, that contains the same files and subfolders as originally found in C:\Scripts. The MoveHere method uses two parameters:
    • The name of the folder being moved (C:\Scripts).
    • The optional constant FOF_CREATEPROGRESSDLG. This causes the Move Files dialog box to be displayed as the contents of C:\Scripts are being moved.

Listing 11.13   Moving Folders Using the Shell Folder Object

1 2 3 4 5 
Const FOF_CREATEPROGRESSDLG = &H0& TargetFolder = "D:\Archive"  Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.NameSpace(TargetFolder)  objFolder.MoveHere "C:\Scripts", FOF_CREATEPROGRESSDLG

send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

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