How to put a directory structure into a .txt file

I have a directory:

/essbase/app/alloc/alloc
/essbase/app/alloc/test
/essbase/app/test/user
/essbase/app/z_itgis/z_test


How do I script up a way to create a text file that will be:

alloc,alloc
alloc,test
test,user

Thus it dynamically reads anything after the /app, then puts the first directory in the first column, then the second in the second column.  If there is multiple subdirectories after the /app then it just builds new lines for each one.  Then it just keeps going until it no more directories exist in the /app directory.  It ignores all directories that begin with 'z_' .


Thanks,

Sam
elwayisgodAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
#!/usr/bin/perl
use File::Find;
find(sub{
($File::Find::prune = /^z_/)
||
-d && (split'/',$File::Find::name)>2 && print join(',',@_[3..$#_]),"\n"
},"/essbase/app");
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
elwayisgodAuthor Commented:
Whoops.  Forgot to mention I'm on Windows so my directories are:

C:\essbase\app\alloc\alloc
C:\essbase\app\alloc\test
C:\essbase\app\test\user
C:\essbase\app\z_itgis\z_test


Sorry, just came from Sun to a windows environment.  Thus the problem.

Sam
0
NopiusCommented:
It's not a problem if you install UnxUtils: http://unxutils.sourceforge.net/
It's a set of unix utilities for Windows (very lightweight, not a cygwin).

basename, dirname, sed and awk are all there
0
ozoCommented:
The above perl code works in either Unix or Windows
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.