1

I have a folder containing few files. I would like to get, for each file, a list of all the properties assigned to this file and their values.

I have written these few lines but I am not able to identify the right methods to use in the placeholders MethodIamLookingFor1 (to get list of properties assigned), MethodIamLookingFor2 (to get property name) and MethodIamLookingFor3 (to get property value):

Dim sFolder
sFolder = "C:\Batch_DEV\to"
Dim objFSO, objDir, listObjFiles, objFile

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDir = objFSO.GetFolder(sFolder)
Set listObjFiles = objDir.Files

For Each objFile In listObjFiles
        Wscript.Echo objFile.name & ": "
        listProperties = objFile.MethodIamLookingFor1 
            For Each objFileProperty In listProperties
                Wscript.Echo "property name is: " & objFileProperty.MethodIamLookingFor2
                Wscript.Echo "property value is: " & objFileProperty.MethodIamLookingFor3
            Next
    Next

Could you please help? thanks!

Massyle Djama
  • 39
  • 1
  • 7
  • 1
    Look at this post : http://stackoverflow.com/questions/5651890/using-vba-to-get-extended-file-attributes – Sorceri Dec 29 '15 at 16:36
  • @Sorceri You know the difference between VBA and VBScript right? – user692942 Dec 29 '15 at 20:43
  • @Lankymart You do realize that it can easily be converted to work in VBScript...right?..... – Sorceri Dec 29 '15 at 21:19
  • @Sorceri No really, you'd think I would know that with over 70+ answers in VBScript. Geez. The point is why direct someone to a Excel VBA question who might not know the difference and try to use the code outright? – user692942 Dec 29 '15 at 21:32

3 Answers3

2

Code from Using VBA to get extended file attributes

ignore the VBA keyword as it can be converted to VBScript with little effort. See below.

Dim fso
Dim txtStream
Dim sFile
Dim oShell

Set oShell = CreateObject("Shell.Application")
Set fso = CreateObject("Scripting.FileSystemObject")
Dim oDir
Set oDir = oShell.Namespace(pathToFolder)
Set txtStream = fso.OpenTextFile(pathToTextFile, 2, True, -2)

For Each sFile In oDir.Items
    For i = 0 To 40
       txtStream.WriteLine i & " : " & oDir.GetDetailsOf(oDir.Items, i) & " : " & oDir.GetDetailsOf(sFile, i)
    Next
Next
Community
  • 1
  • 1
Sorceri
  • 7,870
  • 1
  • 29
  • 38
1

I don't recall VBScript as having a property that can be used to enumerate file properties. VB6 contained the FileInfo object that would have allowed for that.

Using VBScript you will need to specify each property you want. The files properties are listed on MSDN.

1

thanks, I have used the GetDetailsOf instruction you indicated and adapted my code to use https://technet.microsoft.com/en-us/library/ee176615.aspx inputs

Dim sFolder
sFolder = "C:\Batch_DEV\to"

Set objShell = CreateObject("Shell.Application")
Set objDir = objShell.Namespace(sFolder)

For Each strFileName in objDir.Items
    Wscript.Echo objDir.GetDetailsOf(strFileName, 0) & ":"
    For i = 0 To 10
        Wscript.Echo  vbtab & "property name is: " & objDir.GetDetailsOf(objDir.Items, i)
        Wscript.Echo  vbtab & "property value is: " & objDir.GetDetailsOf(strFileName, i)
    Next
Next

so at the end the methods are:

  • MethodIamLookingFor1 ==> GetDetailsOf(objDir.Items, i)
  • MethodIamLookingFor2 ==> GetDetailsOf(objDir.Items, i)
  • MethodIamLookingFor3 ==> GetDetailsOf(strFileName, i)

I have added a vbtab to enhane the output and here is the result:

test.txt:
         property name is: Nome
         property value is: test.txt
         property name is: Dimensione
         property value is: 351 byte
         property name is: Tipo elemento
         property value is: File TXT
         property name is: Ultima modifica
         property value is: 23/12/2015 14:34
         property name is: Data creazione
         property value is: 29/12/2015 09:30
         property name is: Data ultimo accesso
         property value is: 29/12/2015 09:30 word 
sample.docx:
         property name is: Nome
         property value is: word sample.docx
         property name is: Dimensione
         property value is: 11,1 KB
         property name is: Tipo elemento
         property value is: Documento di Microsoft Word
         property name is: Ultima modifica
         property value is: 10/12/2015 16:24
         property name is: Data creazione
         property value is: 29/12/2015 09:31
         property name is: Data ultimo accesso
         property value is: 29/12/2015 09:31

Many thanks for the support!

hollopost
  • 569
  • 9
  • 28
Massyle Djama
  • 39
  • 1
  • 7
  • 3
    The deceleration of array in line "Dim listProperties(10)" do nothing in your script . And for next loop not any benefit in the script result. remove this 4 lines . – hollopost Oct 02 '18 at 21:55