Windows Vista Forums

Can't see hidden shell.application folder items.

  1. #1


    Paul Randall Guest

    Can't see hidden shell.application folder items.

    Hi,

    I'm having trouble seeing hidden files with
    oShellApp.NameSpace(sFolderPath).Items.

    I'm running WXP SP2 with default folder view properties set to display
    hidden files and folders and NOT hide protected operating system files.
    Folder view shows hidden and system files.

    What changes should I make to my script so the Items collection will include
    hidden items, so that I can use the shell folder's CopyHere method to copy
    those files to a .ZIP file?

    The sample script below should be put in an empty folder. It will create
    one subfolder there, create four small text files in that folder, and set
    these file's attributes to various combinations of hidden and system. It
    then displays the attributes using the attrib command, which sees all four
    files, and using oShellApp.NameSpace(sFolderPath).Items properties, which
    does not see the hidden files. This script should be run with CScript.

    '---------------------------------
    Option Explicit
    Dim objFSO, sFolderPath
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Dim objWshShell
    Set objWshShell = CreateObject("Wscript.Shell")
    Dim oExec, sResults
    Dim sCmd

    Dim sFolderName: sFolderName = "4-Files"
    If objFSO.FolderExists(sFolderName) Then
    objFSO.DeleteFolder(sFolderName)
    End If
    objFSO.CreateFolder(sFolderName)
    fOverWrite sFolderName & "\hidden.txt", "This is a hidden file."
    fOverWrite sFolderName & "\system.txt", "This is a system file."
    fOverWrite sFolderName & "\hidn-sys.txt", "This is a hidden system file."
    fOverWrite sFolderName & "\normal.txt", "This is a normal file."

    sCmd = "attrib +h " & sFolderName & "\Hidden.txt"
    Set oExec = objWshShell.Exec(sCmd)
    sCmd = "attrib +h +s " & sFolderName & "\Hidn-Sys.txt"
    Set oExec = objWshShell.Exec(sCmd)
    sCmd = "attrib +s " & sFolderName & "\System.txt"
    Set oExec = objWshShell.Exec(sCmd)
    sCmd = "attrib " & sFolderName & "\*.*"
    Set oExec = objWshShell.Exec(sCmd)
    sResults = oExec.StdOut.ReadAll()
    wScript.echo "Created folder " & sFolderName & _
    " containing four text files with various" & vbCrLf & _
    "combinations of hidden and system attributes." & _
    vbCrLf & vbCrLf & sResults

    sFolderPath = objFSO.GetParentFolderName(WScript.ScriptFullName) & _
    "\" & sFolderName

    Dim oShellApp
    Set oShellApp = CreateObject("Shell.Application")

    Dim sMsg
    Dim oItem, ocItems
    Set ocItems = oShellApp.NameSpace(sFolderPath).Items
    Wscript.Echo "According to oShellApp.NameSpace(sFolderPath).Items," & _
    vbcrlf & "count of items in " & sFolderPath & " is " & ocItems.Count & _
    ". They are:"
    For Each oItem In ocItems
    WScript.Echo oItem.Path
    Next
    WScript.Echo
    WScript.Echo "How to make oShellApp.NameSpace(sFolderPath).Items" & _
    vbCrLf & "see hidden items?"

    Sub fOverWrite(sFileName, sAnsiText)
    objFSO.CreateTextFile(sFileName, True, False).Write(sAnsiText)
    End Sub


    '--------------------------------------------

    Thanks for any help you can give me.

    -Paul Randall





      My System SpecsSystem Spec

  2.   


  3. #2


    Todd Vargo Guest

    Re: Can't see hidden shell.application folder items.

    Paul Randall wrote:

    > Hi,
    >
    > I'm having trouble seeing hidden files with
    > oShellApp.NameSpace(sFolderPath).Items.
    >
    > I'm running WXP SP2 with default folder view properties set to display
    > hidden files and folders and NOT hide protected operating system files.
    > Folder view shows hidden and system files.
    >
    > What changes should I make to my script so the Items collection will
    include

    > hidden items, so that I can use the shell folder's CopyHere method to copy
    > those files to a .ZIP file?
    ....

    Add this to the end of your script.

    Dim f,fc,f1
    Set f = objfso.GetFolder(sFolderPath)
    Set fc = f.Files
    For Each f1 in fc
    WScript.Echo f1.path
    Next

    --
    Todd Vargo
    (Post questions to group only. Remove "z" to email personal messages)


      My System SpecsSystem Spec

  4. #3


    Paul Randall Guest

    Re: Can't see hidden shell.application folder items.


    "Todd Vargo" <tlvargo@xxxxxx> wrote in message
    news:OlQtiV7mJHA.2560@xxxxxx

    > Paul Randall wrote:

    >> Hi,
    >>
    >> I'm having trouble seeing hidden files with
    >> oShellApp.NameSpace(sFolderPath).Items.
    >>
    >> I'm running WXP SP2 with default folder view properties set to display
    >> hidden files and folders and NOT hide protected operating system files.
    >> Folder view shows hidden and system files.
    >>
    >> What changes should I make to my script so the Items collection will
    > include

    >> hidden items, so that I can use the shell folder's CopyHere method to
    >> copy
    >> those files to a .ZIP file?
    > ...
    >
    > Add this to the end of your script.
    >
    > Dim f,fc,f1
    > Set f = objfso.GetFolder(sFolderPath)
    > Set fc = f.Files
    > For Each f1 in fc
    > WScript.Echo f1.path
    > Next
    Thanks, Todd
    I knew that FSO can see hidden files, but I was so fixated on
    shell.application folder items that I neglected to look at the documentation
    for the CopyHere method, which allows specifying full paths or items. For
    my current application, all the files I want to zip are in a single folder.
    So I can use CopyHere to copy the entire items collection, then scan the
    source folder for hidden files and folders, and pass their FSO full paths to
    the CopyHere method one at a time. Besides making the code more
    complicated, I think it may slow down the process because each use of the
    CopyHere method (I'm guessing) causes a rewrite of the entire zip file. It
    would be nice if I could get an entire folder's contents zipped with a
    single CopyHere using the standard tools included with WXP Home.

    I tried one other thing: putting the unhidden folder of things I want zipped
    inside an unhidden folder, and using my script to zip the contents of that
    outer unhidden folder. It has no problem with folder items containing
    hidden things. This creates an extra folder level in the zip file but gets
    the job done with a single CopyHere.

    -Paul Randall



      My System SpecsSystem Spec


Can't see hidden shell.application folder items.

Similar Threads
Thread Forum
FTP - Using Win32 Shell.Application VB Script
shell.application VB Script
can shell.application do this? PowerShell
If the pst files are in a hidden folder or are hidden how can be seen or search for ? Browsers & Mail
Re: Have a command shell open but hidden Vista General