Windows Vista Forums

Sorting files in a folder

  1. #1


    WVR Guest

    Sorting files in a folder

    Hello,

    How do I sort files in a folder with VBS? I tried the following but that did
    not work:

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}\\" & strComputer & "\root\cimv2")

    Set colFiles = objWMIService.ExecQuery _
    ("Select * from Win32_FileSpecification order by CreationDate")

    For Each objFiles in colFiles
    Wscript.Echo objFiles.Name
    Next


    The problem I have is that the query results in (8, 1) (null): 0x80041017
    And I cannot specify the folder name.



    Any help is appreciated.

    With kind regards,
    WVR

      My System SpecsSystem Spec

  2. #2


    Richard Mueller [MVP] Guest

    Re: Sorting files in a folder

    WVR wrote:

    > How do I sort files in a folder with VBS? I tried the following but that
    > did
    > not work:
    >
    > strComputer = "."
    > Set objWMIService = GetObject("winmgmts:" _
    > & "{impersonationLevel=impersonate}\\" & strComputer & "\root\cimv2")
    >
    > Set colFiles = objWMIService.ExecQuery _
    > ("Select * from Win32_FileSpecification order by CreationDate")
    >
    > For Each objFiles in colFiles
    > Wscript.Echo objFiles.Name
    > Next
    >
    >
    > The problem I have is that the query results in (8, 1) (null): 0x80041017
    > And I cannot specify the folder name.
    The WMI Query Language does not support sorting. You can use a disconnected
    recordset to sort. See this link:

    http://www.microsoft.com/technet/scr..._ent_piij.mspx

    --
    Richard Mueller
    MVP Directory Services
    Hilltop Lab - http://www.rlmueller.net
    --



      My System SpecsSystem Spec

Sorting files in a folder

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting files in a folder rmo555 Vista General 0 31 Jan 2010
Auto sorting of files in folder AMG Vista General 19 03 Nov 2009
Folder Sorting Dzomlija Tutorials 8 16 Oct 2008
File and Folder Sorting...Help! Geoff Stone Vista General 4 06 Jul 2007