Link to home
Start Free TrialLog in
Avatar of elwayisgod
elwayisgodFlag for United States of America

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of elwayisgod

ASKER

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
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
The above perl code works in either Unix or Windows