Ruriko
Programmer
- Aug 17, 2012
- 7
I am trying to make the script to scan a folder and list only image files such as jpg, png, gif.
What this script does it reads a txt file contain the path to the folders. It will scan the folder and it will print the list of files into a new txt file. What I want is list only image files.
Can anyone give me the proper code?
What this script does it reads a txt file contain the path to the folders. It will scan the folder and it will print the list of files into a new txt file. What I want is list only image files.
Code:
Dim fso, ObjFolder, ObjOutFile, ObjFiles, ObjFile, outputFile, inputFileList
Const ForReading = 1, ForWriting = 2, ForAppending = 8, CreateIfNeeded = true
inputFileList = "list.txt"
outputFile = "C:\Users\Susan\Documents\iMacros\Macros\WindowsFiles.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set objTextFile = fso.OpenTextFile(inputFileList, ForReading)
Do Until objTextFile.AtEndOfStream
sFolderName = objTextFile.Readline
wscript.Echo "writing contents of " & sFolderName
writefilenames(sFolderName)
Loop
function writefilenames(sFolderName)
Set ObjFolder = fso.GetFolder(sFolderName)
If fso.FileExists(outputFile) Then
Set ObjOutFile = fso.OpenTextFile(outputFile, ForAppending)
Else
Set ObjOutFile = fso.OpenTextFile(outputFile, ForWriting, CreateIfNeeded)
End If
Set ObjFiles = ObjFolder.Files
For Each ObjFile In ObjFiles
ObjOutFile.WriteLine(ObjFile.Path)
Next
ObjOutFile.Close
end function
Can anyone give me the proper code?