Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Can't see hidden shell.application folder items.

Reply
 
Old 03-02-2009   #1 (permalink)
Paul Randall


 
 

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
Old 03-02-2009   #2 (permalink)
Todd Vargo


 
 

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

Paul Randall wrote:
Quote:

> 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
Quote:

> 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
Old 03-03-2009   #3 (permalink)
Paul Randall


 
 

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


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

> Paul Randall wrote:
Quote:

>> 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
Quote:

>> 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
Reply

Thread Tools


Similar Threads
Thread Forum
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
problem with shell.application PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46