My requirement is to search entire c:\ drive and export the entries to a .txt file format. The challange is user needs to input the filename in a dialog box.
Following is the script that I created, when I run this I am getting an error permission denied.
'On Error Resume Next
Option Explicit 'force all variables to be declared
Const ForWriting = 2
Dim objFSO
Dim wshell
Set wshell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
wshell.ExpandEnvironmentStrings("%SYSTEMDRIVE%")
Dim objTS 'Text Stream Object
Set objTS = objFSO.OpenTextFile("C:\Eurofins\Logs\Output.txt", ForWriting, True)
Recurse objFSO.GetFolder("%SYSTEMDRIVE%")
objTS.Close()
Sub Recurse(objFolder)
Dim objFile, objSubFolder
For Each objFile In objFolder.Files
If LCase(objFSO.GetExtensionName(objFile.Name)) = "ini" Then
objTS.WriteLine(objfile.Path)
End If
Next
For Each objFile In objFolder.Files
If LCase(objFSO.GetExtensionName(objFile.Name)) = "txt" Then
objTS.WriteLine(objfile.Path)
End If
Next
For Each objSubFolder In objFolder.SubFolders
Recurse objSubFolder
Next
End Sub
wshell.ExpandEnvironmentStrings("%SYSTEMDRIVE%")but you don't assign it to a variable, you then callRecurse objFSO.GetFolder("%SYSTEMDRIVE%")without the expanded version which you should have got by assigning the variable in the first place. It will error because FSO doesn't know what%SYSTEMDRIVE%is, that's why you usewshell.ExpandEnvironmentStrings("%SYSTEMDRIVE%").