ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

Directory of folders inside a folder limited by depth showing complete path

(1/3) > >>

I know this has got to be a simple thing.  Somehow I got involved in running a power-shell batch file to create this list but unfortunately I can no longer finds it.
It seems to me that something like dir *. /s was how it was once done the only problem is I need it to stop after 2 levels, maybe 3.  but no more than 4.
Is there a way to limit the depth of the replies to a given number of levels?  If there were, that simple dir command would be all I need.  Any info appreciated.
the complete path part would be nice but not absolutely necessary.

Get-ChildItem \*                  <- one level
Get-ChildItem \*\*               <- two levels
Get-ChildItem \*\*\*            <- three levels

etc, etc

You can substitute dir for Get-ChildItem, (dir is just an alias for it), but using Get-ChildItem differentiates it from a normal DOS command.

From StackOverflow:

Get-ChildItem \* | % { if ($_.Attributes -eq "Directory") { Write-Host $_.FullName } }                <- one level from root, directories only, full path output one per line
Get-ChildItem .\* | % { if ($_.Attributes -eq "Directory") { Write-Host $_.FullName } }               <- one level from current, directories only, full path output one per line

Get-ChildItem \*\*\*\* | % { if ($_.Attributes -eq "Directory") { Out-File d:\out.txt -append -inputobject $_.FullName } }

The above will output normal folders to 4 levels deep to a file called D:\out.txt <- change as you will.

C:\Websites\\empty directory\JudithG\aerogel

I felt if i gave an example it might help.  This is what I get..  Then I have to get rid of the "c:\websites"
delete the "\emptyfolder"
change the slashes from back to forward
to end up with
a list of websites that is clickable

But there are about 100 of these  maybe 5 under each name, maybe 20 names.  This is why i was trying to automate it

even after I get the list, it has to be edited as above to make it useful to the auditors.

notepad++ (and others) make this not so bad.
just a few replace "text" with "" so not worth the effort of writing a full scale utility to get further.  Just getting that list to run with was a Godsend and I thank you all

Oh well.  I did try every one and I thank all of you but none of them provide the simple structure I need as I explained.  I did try the \* solution but did not produce useful list.  I also tried the 4wd suggestion of using the batch file I already had which was so bad because I could see exactly what I wanted fly by on the screen but not get captured.  the addition of >>capture.txt at the point suggested failed to go more than I level deep no matter what variable I used.  it was a perfect starter.  but using the example above  it would show all the websites\users names\ then stop.  if it had gone one more level it would have worked.
Maybe over the weekend something will come about but thanks to all again 

You should be able to get the list easily enough with the "find" program from the ports of Gnu utilities.  I think I attached just that file below, 7-zipped (please see the site for the appropriate license).  A command line like "find -type d -maxdepth 4" would give you four levels of directories.  Then add gsar (general search and replace) for your edits.  Run this from the top level of your folder structure:

find -type d -maxdepth 4 > ~1.txt
gsar -sC:\Websites\ -r ~1.txt ~2.txt
gsar -s"empty directory\" -r ~2.txt ~3.txt
gsar -s\ -r/ ~3.txt final.txt
del ~1.txt
del ~2.txt
del ~3.txt

--- End quote ---

Is this close to what you need?  (Forgive if not, it has been a long week!)


[0] Message Index

[#] Next page

Go to full version