The code is as below
=====================================================
Sub getfilename()
Dim fso, folder, files, OutputFile
Dim strPath
Myuser = Environ("userprofile")
Myuserdesktop = Myuser & "\Desktop"
' Create a FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
' Define folder we want to list files from
strPath = "C:\Users\Public\Pictures\Sample Pictures"
Set folder = fso.GetFolder(strPath)
Set files = folder.files
' Create text file to output test data
Set OutputFile = fso.CreateTextFile(Myuserdesktop & "\ScriptOutput.txt", True)
' Loop through each file
For Each Item In files
' Output file properties to a text file
OutputFile.WriteLine (Item.Name)
Next
' Close text file
OutputFile.Close
' View text file
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute Myuserdesktop & "\ScriptOutput.txt"
End Sub
=====================================================
No comments:
Post a Comment