topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Saturday December 14, 2024, 1:32 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Directory of folders inside a folder limited by depth showing complete path  (Read 19141 times)

questorfla

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
  • Fighting Slime all the Time
    • View Profile
    • Donate to Member
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.


4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
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.
« Last Edit: October 01, 2013, 06:51 PM by 4wd »

questorfla

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
  • Fighting Slime all the Time
    • View Profile
    • Donate to Member
C:\Websites\www.xxxxxxx.com\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

www.xxxxx.com/judithg/aerogel

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

questorfla

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
  • Fighting Slime all the Time
    • View Profile
    • Donate to Member
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 

x16wda

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 888
  • what am I doing in this handbasket?
    • View Profile
    • Read more about this member.
    • Donate to Member
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

Is this close to what you need?  (Forgive if not, it has been a long week!)
vi vi vi - editor of the beast

questorfla

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
  • Fighting Slime all the Time
    • View Profile
    • Donate to Member
X16Wda:
Maybe.  I don't know a lot about using ?gnu?  I can try.  I have a working solution but it is tedious.  Worse.  after trying so many, when this on worked, it was a sort of "half worked" so I did not look at the results till later.  It got me by but only with a lot of editing.  In my comment where I show what I would "like" about two entries above yours, it shows what I can usually get and what i need to end up with.  I ran something that created what I THINK was actually an error report but it still was perfect after editing.  the lines read "processing "                                <   c:\wamp\htdocs\websites\"The wwwsitename"\emptydirectory\usersname\foldermname  >  This can be multiple edited to remove the first 3 directories and remove the "emptydir" and reverse the "/"'s leaving me with all I wanted :)  now I have to figure out which batch file did it.  I was testing too many.  GSAR isn't in any of the addon packs I have found yet  the commands have to run in a windows environment

questorfla

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
  • Fighting Slime all the Time
    • View Profile
    • Donate to Member
Duh.  I just saw your link getting it now.
Also in looking I found this:          Microsoft SFU (services for Unix).  The 7zip file only had the find command but I needed that too.  I am hoping the Microsoft download has the rest.  Even comes with a windows installer
« Last Edit: October 05, 2013, 04:48 PM by questorfla, Reason: added info »

x16wda

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 888
  • what am I doing in this handbasket?
    • View Profile
    • Read more about this member.
    • Donate to Member
The Unix utils "find" is attached to my message (7-zipped), since it comes in a much bigger package and it is buried inside that package.  I think also that SFU is really much bigger than you want and is more intrusive on your system, especially when you just want a little utility.  The gsar program was linked in the text of the message, it's at http://home.online.no/~tjaberg/, I can attach it too if you have any trouble getting it.

The gsar lines can be edited and modified if they don't do what you need, just let me know!
vi vi vi - editor of the beast

questorfla

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
  • Fighting Slime all the Time
    • View Profile
    • Donate to Member
 ;D  I am SO out of it.  I swear.  X16 I hope you are on tonight.   ;D
I need the smiley where he hits his head on the wall.  This whole setup you sent was a way to fix the output.  I tried everything I knew but it fiercely resisted all attempts to create anything.
After "hitting my head on the wall " a few times, I finally read the instruction for the Unix commands.  Your proggy was a FIX for my output.  :)  OK.
Well, I learned a few interesting facts anyway.  Some (maybe not all) of those commands work fine when just dropped into the windows directory so they can be found in the path.
find and gsar work perfectly when done that way.  All I have to do now is find the batch file that created the file that needed to be edited.  I bet I can even merge the two and in the end get what I want.  That was worth the effort.  I got to laugh at myself for being so nearsighted.  The original batch is here somewhere but I have maybe 50 that all work to some degree.  Anyway, your input was a welcome surprise.  I am sure I will have other uses for all these new commands now

questorfla

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
  • Fighting Slime all the Time
    • View Profile
    • Donate to Member
WOW   :P           I found my way back here.  X16.  If you are on or someone else familiar with his reply.  U was able to use the exact layout from find by running it further down the tree.  no need for the gsar.  however the UNIX output from find uses a "." to separate what I need to be single lines.  each entry is just added to the next with the . separating them.  is there a similar utility that would change the "dot" to be a "carriage return"?  convert a UNIX style output to a DOS style output?  That is all it needs now.  Your Unix command cut this whole thing down to 15 characters on a command line. except for the UNIX output/.

Adding this in case it helps someone else.  Open the .txt file created with any editor other than notepad  (I guess)
I used notepad++ and it opened right up with the lines exactly as I need them.  Thanks for everyones help .
I now have an instant tool to provide a report that used to take e close to 30 minutes to build one line at a time.  :)
« Last Edit: October 05, 2013, 08:46 PM by questorfla, Reason: Found the Answer! »

x16wda

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 888
  • what am I doing in this handbasket?
    • View Profile
    • Read more about this member.
    • Donate to Member
Good deal!!

Now, time to fix that Notepad (ugh!) problem... Grab Notepad Replacer and install it and point it to your notepad++ exe, and you won't have to worry about Notepad Original popping up its ugly head any more...  ;D
vi vi vi - editor of the beast

questorfla

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
  • Fighting Slime all the Time
    • View Profile
    • Donate to Member
Got that too!  Many thanks this is GREAT to finally get something to work right!
But...
I have to start a new topic I guess.  This is a little different.  A problem that a User her pointed me to a great program, I have it all loaded and working as I need it.  But I need a correct htacess format to protect it from outside access.  I will explain in new topic.  But ,many thanks X16.  By the way, I did get the whole batch of UNIX from MS  when I get time, I might go through the rest and see what else might come in handy  :)