FSO Series SIX * * Sample code Detail Code 2

Source: Internet
Author: User
fso| example ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' "" "" "" "" "" "" "" "" "" "" "" ""
'
' Generateallfolderinformation
'
Objective
'
' Generates a string that describes the current state of a folder and all files and subfolders.
'
' Demonstrate the content below
'
'-Folder.path
'-folder.subfolders
'-Folders.count
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Function generateallfolderinformation (Folder)

Dim S
Dim Subfolders
Dim subfolder
Dim Files
Dim File

S = "folder:" & TabStop & Folder.path & newline & newline

Set Files = Folder.files

If 1 = files.count Then
s = S & "There is 1 file" & NewLine
Else
s = S & "There are" & Files.count & "Files" & NewLine
End If

If files.count <> 0 Then

For each File in Files
s = S & Generatefileinformation (File)
Next

End If

Set subfolders = Folder.subfolders

If 1 = subfolders.count Then
s = S & newline & "There is 1 sub folder" & NewLine & NewLine
Else
s = S & newline & "There are" & Subfolders.count & "sub folders" & NewLine & NewLine
End If

If subfolders.count <> 0 Then

For each subfolder in subfolders
s = S & generatefolderinformation (subfolder)
Next

s = S & newline

For each subfolder in subfolders
s = S & generateallfolderinformation (subfolder)
Next

End If

Generateallfolderinformation = S

End Function

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Generatetestinformation
'
Objective
'
' Generates a string that describes the current state of the C:\Test folder and all files and subfolders.
'
' Demonstrate the content below
'
'-filesystemobject.driveexists
'-filesystemobject.folderexists
'-Filesystemobject.getfolder
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Function generatetestinformation (FSO)

Dim TestFolder
Dim S

If not FSO. Driveexists (testdrive) Then Exit Function
If not FSO. FolderExists (Testfilepath) Then Exit Function

Set TestFolder = FSO. GetFolder (Testfilepath)

Generatetestinformation = Generateallfolderinformation (TestFolder)

End Function


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Deletetestdirectory
'
Objective
'
' Clean up the test directory.
'
' Demonstrate the content below
'
'-Filesystemobject.getfolder
'-Filesystemobject.deletefile
'-Filesystemobject.deletefolder
'-Folder.Delete
'-File.delete
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Sub deletetestdirectory (FSO)

Dim TestFolder
Dim subfolder
Dim File

' There are two ways to delete a file:

Fso. DeleteFile (Testfilepath & "\beatles\octopusgarden.txt")

Set File = FSO. GetFile (Testfilepath & "\beatles\bathroomwindow.txt")
File.delete &



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.