Windows Admin Scripting Little Black Book- P5

Windows Admin Scripting Little Black Book- P5:This book may not be duplicated in any way without the express written consent of the publisher, except in the form of brief excerpts or quotations for the purposes of review. The information contained herein is for the personal use of the reader and may not be incorporated in any commercial programs, other books, databases, or any kind of software without written consent of the publisher. Making copies of this book or any portion for any purpose other than your own is a violation of United States copyright laws | Set GetFolder sFOLDER If 0 Then Error connecting to folder sFOLDER VBlf End If End Function Generating a Directory Listing To generate a directory list proceed as follows 1. Create a new directory to store all files included in this example. 2. Download and install the latest version of Windows Script Host from to the new directory. 3. Select Start Run and enter cscript . Here scriptfile is the full path and file name of a script file that contains the following Set FSO CreateObject sDIR directory Set objDIR GetFolder sDIR GoSubFolders objDIR Sub ListFiles objDIR For Each efile in efile Next End Sub Sub GoSubFolders objDIR If objDIR System Volume Information Then ListFiles objDIR For Each eFolder in eFolder GoSubFolders eFolder Next End If End Sub Here directory is the root folder containing the files and folders to list. The subprocedure ListFiles rotates through all the files within the current directory and lists their names. Note You need to append the GetFolder routine listed earlier in this chapter to this script in order for it to run. Tip If you want to send the directory list to a text file you can use the DOS append command when running the script from the command line for example cscript . Deleting a File To delete a file with WSH you can use the DeleteFile method. Here is a subroutine to delete a file Sub DelFile sFILE On Error Resume Next sFILE True If 0 Then Error deleting file sFILE End If End Sub In this script a file deletion is attempted and the user is prompted if any errors occur. Deleting All Files within a Folder To delete all files within a root folder and its subfolders proceed as follows 1. Create a new directory to store all files included in this example. 2. Download and

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.