Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding hidden folders with WScript.Shell

Status
Not open for further replies.

Bryan - Gendev

Programmer
Jan 9, 2011
408
AU
I am using code I found here many years ago - it produces a listing of all folders ( and files) from a selected point on any of my drives. However the list does not contain the system hidden folder 'appdata' and all of its contents. I wish to see that folder and its contents. I can imagine a modification to the code below would do this. I tried opttree.Value = 2 with no apparent change.

Code:
oShell = Createobject("WScript.Shell")
If Thisform.opttree.Value = 1
	oShell.Run('cmd /c '+Iif(Thisform.chkInclude.Value = 0,'tree "','tree /f "')+;
				Thisform._SourceFolder+'" > '+Thisform._TreeFile,2,.T.)
Else
	oShell.Run('cmd /c '+Iif(Thisform.chkInclude.Value = 0,'tree /a "','tree /a /f "')+;
				Thisform._SourceFolder+'" > '+Thisform._TreeFile,2,.T.)
Endif

Can anyone help?
GenDev
 
According to the Help for the Tree command, there are only two parameters that can be passed:

/F to show the files as well as the directories
/A to use ASCII instead of extended characters

You are using both of those, and neither is relevant to the question.

You might be better of using ADIR() rather than shelling out to DOS. Passing "H" in the third parameter will find hidden files and/or directories. See the VFP Help for details.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Gendev, from our discussion you also already know that DIRECTORY() can be nudged to return .T. for hidden folders.

But Mikes advice is good, you just have to also add "D" to the third parameter (cAttribute) to get directories, otherwise you only get files and hidden files. H will mean to also see hidden files and directories, not only hidden files and direectories, so take a look at the result array column 5 where attributes including "H" for hidden are showm.

For example this will create an array that besides many more items also contains the hidden AppData directory of your own userprofile (the one you are logged in to):
Code:
? ADir(laDummy,GetEnv("USERPROFILE")+"\*","HD")

Which reminds me that I asked a question about that, and some older questions you didn't answer yet. Could you be so kind to answer questions in your own interest?

Chriss
 
Chriss,
1
I was hoping to be able to use a prg that I already have that contain s that code. But I don't know if I have the skills to convert to Adir
2
I have not been able to identify the questions I have not answered. I do not mean to be disrespectful.
I have a long post in the other thread.

GenDev


 
GenDev,

I take your point about wanting to use your existing code. But unfortunately there doesn't seem to be any way for the Tree command to display hidden files or folders.

Here is the complete spec. for Tree (which I found here):

Code:
Usage: tree [drive:][path] [/F] [/A] [/Q] [/R] [/T] [/X] [/K]

Options:

[drive:][path]: Specifies the drive and directory to display the tree structure of. 
If no path is specified, the current directory is used.
  /F: Displays the names of the files in each folder.
  /A: Uses ASCII instead of extended characters.
  /Q: Encloses directory names in double quotation marks.
  /R: Displays the tree structure in a reverse order.
  /T: Displays the tree structure with the file sizes.
  /X: Prints the short names of files and directories.
  /K: Displays the sizes of folders in kilobytes.

By the way, /A switch only affects the line-drawing characters, the ones used to show the structure of the tree. With the switch in place, lines are shown as pipes, bars and slashes rather than actual line characters. (This is not relevant to your question, but I thought I would mention it anyway.)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,
Thanks for that.
This is the function's screen. Really useful and fast. Note the absence of appdata under user bryan

tree_qdk5fs.png

treee2_cte15s.png


GenDev
 
???

The one screen shows the tree from U:pATHWIZ11\..., not at all related to user profiles, the other is a GETDIR() rooted at the user profile. Yes, GETDIR isn't Windows Explorer, it's showing no hidden folders. What does this help to compare these? Also, you ignored what Mike said:
Mike Lewis said:
But unfortunately [highlight #FCE94F]there doesn't seem to be[/highlight] any way for the Tree command [highlight #FCE94F]to display hidden files or folders[/highlight].
I see no hidden files or folders displayed, it's not even likely there are any hidden folders or files.

Hidden is not an atrtribute that is inherited, if you don't yet have realzed that and the hidden attribute of appdata was never your problem.

Your post is pointless to me, it does not prove or show anything that is enlightening.

Chriss
 
Chriss,
I was simply illustrating the program that I have the prg for, initially hoping to be able to amend it to show hidden folders.
The images are just illustrations nothing else.
I am on a learning curve and have learned many things from this forum.

GenDev
 
I was simply illustrating the program that I have the prg for, initially hoping to be able to amend it to show hidden folders.

The burden of all our replies in this thread is that can't do that. You will just have to swallow hard and abandon your existing code and find another approach, in particular using ADIR() as both Chris and I have suggested.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
gendev said:
[highlight #FCE94F]initially[/highlight] hoping to be able to amend it to show hidden folders.
Initially, I hope that means you realized that it's not possible. As Mike also told you.

I can understand that you already made those screenshots and prepared your post, it's still pointlesss to show how the tree result looks, as it doesn't change the fact the tree command has no feature to also show the hidden attribute.

Chriss
 
Chriss,
C> I hope that means you realized that it's not possible

Yes, I do - thankyou

GenDev
 
To include the 'appdata' folder and its contents in your listing, you might want to try modifying the tree command parameters. Instead of focusing on opttree.Value, try adjusting the /a and /f options in your cmd /c command.
For ex.
oShell.Run('cmd /c '+Iif(Thisform.chkInclude.Value = 0,'tree /a "','tree /a /f "')+;
Thisform._SourceFolder+'" > '+Thisform._TreeFile, 2, .T.)
 
Bigrsmith said:
try adjusting the /a and /f options in your cmd /c command.

But that still doesn't solve the problem. As we have already said (several times):

/a only affect the line-drawing characters used in the outtut; it has nothing to do with the choice of files that are actually displayed.

/f just says to show files as well as directories.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
If you're using Win10 or higher use powershell instead of batch scripting.
Code:
 Get all directories from the current directory, recursively
$directories = Get-ChildItem -Path . -Directory -Recurse -Force

# Filter out the hidden directories
$hiddenDirectories = $directories | Where-Object { $_.Attributes -match 'Hidden' }

# Print the full path of each hidden directory
foreach ($dir in $hiddenDirectories) {
    Write-Output $dir.FullName
}

Best Regards,
Scott
MSc ISM, MIET, MASHRAE, CDCAP, CDCP, CDCS, CDCE, CTDC, CTIA, ATS, ATD

"I try to be nice, but sometimes my mouth doesn't cooperate.
 
Scott,

Thanks for your code but it doesn't compile - I get an error re 'Unrecognised command verb'...

GenDev
 
Aren't we missing the simplest solution?

Instead of the Tree command, use the old-fashioned Dir:

[tt]DIR c:\source /A /S[/tt]

where c:\source is the source directory. /A will find files regardless of attributes (so, it will include hidden files and folders). /S does recursion into sub-directories.

Plug that into your oShell.Run in place of the Tree command.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Well, yes and no. Why resort to Shell or Powershell commands or scripts at all, if ADIR provides the information of hidden folders, too?

Chriss
 
Well, the advantage of DIR (and of Scott's solution) is that it handles the recursion automatically, whereas ADIR() requires you to program that yourself (not that it's particularly difficult).

On the other hand, ADIR() has the advantage that it sends the results to an array, which is very easy to manipulate. It's also good to use native VFP functions rather than shelling out to DOS or PowerShell where possible.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top