• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Can't see hidden shell.application folder items.

P

Paul Randall

#1
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 Computer

T

Todd Vargo

#2
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 Computer

P

Paul Randall

#3
"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 Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)