getting a list of files in a folder with their tag properties

Answered getting a list of files in a folder with their tag properties

  • Thursday, June 14, 2012 3:29 AM
     
     

    Hi,

    I am a newbie to powershell but nevertheless, I have written a very simple code using it. I'm very impressed by it.

    My situation is that I have lots of different photos in a folder on Windows 7. And I know that on Windows 7, photos can be tagged with a name so that they can be easily searched through the Windows Explorer. So what happens is all of these photos have been tagged with a name by different users. What I'd like to be able to do is how to get a whole list of photos along with their "tag" properties, and then save it in a csv format for searching and sorting purposes.

    Any help would be greatly appreciated.

    Thank you very much

All Replies

  • Thursday, June 14, 2012 4:48 AM
     
     

    Microsf S4earch can search the tag properties.  Why not look it up and learn how to use it.  It is pre-installed on Windows 7.


    ¯\_(ツ)_/¯

  • Thursday, June 14, 2012 5:27 AM
     
     

    Thanks jrv for your reply.

    I guess I can ask the users to use the search but like you said I need to learn more on how to use it. The problem is the tags for many of these photos might have wrong spelling. I thought if I could get them all and save it as csv file which I can then open it using Excel spreadsheet. In spreadsheet, I could use the sorting feature to fix them all and later perhaps for searching purpose.

    Sorry jrv, for curiosity's sake, can I confirm with you that this is not possible to do or it just involved a lot more coding.

    Thank you

  • Thursday, June 14, 2012 8:36 AM
     
     Answered

    If you want to do it the hard way start here:

    http://gallery.technet.microsoft.com/scriptcenter/4a4cb944-2342-4f80-a2c6-44be76185825

    It is easier to just run a search query for all image files and dump that to a CSV.


    ¯\_(ツ)_/¯

  • Friday, June 15, 2012 3:07 AM
     
     Proposed Answer

    Thank you JRV for your reply.

    Hooray, tt works really great. That's exactly what I need. Thank you for sharing the script.

    However, when I want to write them into a .csv file, I got runtime error with message saying "invalid procedure call or argument"

    Here is the code that I have modified based on the script you gave

    Dim arrHeaders(34)
    Dim myString
    Dim OutputFile
     
    ' Create a FileSystemObject
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set objShell = CreateObject("Shell.Application")
    ' Define folder we want to list files from
    Set objFolder = objShell.Namespace("C:\scripts")

    ' Create text file to output test data
    Set OutputFile = fso.CreateTextFile("GetFilesProperties.csv", True)

    myString = ""

    For i = 0 to 33
        arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i)
    Next
     
    For Each strFileName in objFolder.Items
        For i = 0 to 33
        myString = myString & objFolder.GetDetailsOf(strFileName, i)
        myString = myString & ","
     
        Next
        OutputFile.Writeline(myString)
        OutputFile.Writeline("")
    Next

    ' Close text file
    OutputFile.Close

    From the error messages, I think it implies that it doesn't recognized Writeline() function. I wonder how to write data into a text file or csv file.

    Thank you in advance

  • Friday, June 15, 2012 4:39 AM
     
      Has Code

    I told you that it wan't going to be easy.  There is no way to answer your question when you don't post the whole error message. 

    Start here:

    '
    ' Name: GetFileProperties.vbs
    '
    ' runscript to a file for results
    '    GetFileProperties.vbs > output.csv
    '  
    Set objShell = CreateObject("Shell.Application") 
    Set objFolder = objShell.Namespace("F:\Projects\My Pictures") 
    For i = 0 to 33 
        wscript.stdout.write """" & objFolder.GetDetailsOf(objFolder.Items, i) & ""","
    Next 
    wscript.stdout.WriteLine
    For Each strFileName in objFolder.Items 
        For i = 0 to 33 
            wscript.stdout.write """" & objFolder.GetDetailsOf(strFileName, i) & ""","
        Next
        wscript.stdout.WriteLine
    Next


    ¯\_(ツ)_/¯

  • Friday, June 15, 2012 6:08 AM
     
     

    Sorry jrv that I did not post the whole error message.

    By the way, After trying out your another script above, I got a different error message as follows

    Line: 9 (which is at the code: wscript.stdout.write """" & objFolder.GetDetailsOf(objFolder.Items, i) & """,")

    char: 5

    error: The handle is invalid

    code: 80070006

    Source: (null)

    Thank you very much for your help

  • Friday, June 15, 2012 6:52 AM
     
     Answered

    You have system problemsor did you change the code?  It runs on any system.  FI you do not change a single character you will likely get a different error message.  That error says that something is altering the handle to the stdout.  Other issues that can cause this are disk corruption or using the wrong kind of a disk.,  Thsi code will not work on a USB FAT drive or on a converted MAc drive.  It will also not work on device storage like cell phones and iPods.  It will only work on true NTFS volumes.

    I noted that you should be using the search provider as it has more techniques for managing the information and will let you query the files in very sophisticated ways.  MS Serch is an end user tool.  The 'SHell' namespaces is usable but requires a good sence of teh underlying technology.  It is not an end user tool.

    It is also possible that you are using the wrong type of file or you may have an AV system that is interfering.  You will have to troubleshoot this yourself as it is not a direct scripting issues.


    ¯\_(ツ)_/¯