Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to put a directory structure into a .txt file

Posted on 2006-04-12
6
Medium Priority
?
213 Views
Last Modified: 2010-04-17
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
0
Comment
Question by:elwayisgod
  • 2
4 Comments
 
LVL 85

Accepted Solution

by:
ozo earned 500 total points
ID: 16439680
#!/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
 

Author Comment

by:elwayisgod
ID: 16439755
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
 
LVL 27

Expert Comment

by:Nopius
ID: 16442336
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
 
LVL 85

Expert Comment

by:ozo
ID: 16442559
The above perl code works in either Unix or Windows
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
Progress
Screencast - Getting to Know the Pipeline

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question