我已经能够提取文件夹中所有文件的信息以及该特定文件夹的所有子文件夹的信息,但是当我想提取所有文件和文件夹的信息(即文件类型、文件路径、文件大小和文件名)时一个特定的目录,我做不到。它说许可被拒绝。
脚本如下:
Option Explicit
Dim objFSO,objf,objfolder, objFile, strFileProperties, strFiles,OBJFLD,objfile2
dim objf1,objfile1,objtextfile,strfolderproperties,objsubfld,objfl,objfl1,strfileproperties2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objf= objFSO.Getfolder("C:\")
set OBJFLD=objf.subfolders
for each objfolder in OBJFLD
strFolderproperties =_
strFolderproperties & "Number of files: " & objFolder.Files.Count & VbCrLf
set objfile2=objfolder.files
for each objfile in objfile2
' Display generel file properties of every subfld
strFileProperties = strFileProperties & "File name: " & objFile.Name & VbCrLf
strFileProperties = strFileProperties & "File path: " & objFile.Path & VbCrLf
strFileProperties = strFileProperties & "File size: " & objFile.Size & " bytes" & VbCrLf
strFileProperties = strFileProperties & "File type: " & objFile.Type & VbCrLf & vbcrlf
next
next
Set objf= objFSO.Getfolder("C:\")
set OBJfl=objf.files
for each objfl1 in OBJfl
'display properties of the files of the main folder
strFileProperties2 = strFileProperties2 & "File name: " & objfl1.Name & VbCrLf
strFileProperties2 = strFileProperties2 & "File path: " & objFl1.Path & VbCrLf
strFileProperties2 = strFileProperties2 & "File size: " & objFl1.Size & " bytes" & VbCrLf
strFileProperties2 = strFileProperties2 & "File type: " & objFl1.Type & VbCrLf & vbcrlf
next
set objf1=objfso.getfolder("E:\logs3")
set objfile1=objfso.getfile( "E:\logs3\database.txt")
set objf1=nothing
set objfile1=nothing
set objtextfile=objfso.opentextfile("E:\logs3\database.txt",8,true)
objtextfile.writeline(strfileproperties)
objtextfile.writeline(strfileproperties2)
objtextfile.close
set objf1=objfso.getfolder("E:\logs3")
set objfile1=objfso.getfile( "E:\logs3\database.txt")
set objf1=nothing
set objfile1=nothing
set objsubfld=objfso.opentextfile("E:\logs3\database.txt",8,true)
objsubfld.writeline(strfolderproperties)
objsubfld.close
注意:当我使用它来提取除整个目录之外的任何文件夹的文件信息时,此脚本有效!
有什么解决办法吗?是否可以获取目录的所有文件和文件夹的信息?
错误信息如下:
line:15
character:12
error:permission denied