Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I wanted to know how to print out the directories and all teh files in unix in a certain way.In my case I have a used ls -R > file.txt and then I wanted to read each line and output it in a certain way.
(ex.1st_dir|root|1st_dir|Ariel|10|0|0|0|True|open|"www.ign.com"|....)Well as you might have noticed I am trying to
make an html page that shows my directories and files dynamically in a tree menu sort of way.Problem is I am pretty new to unix scripting and I dont know how to read or write(or at least this advanced).
Help would be GREATLY appreciated,
Veneet

Im not sure what exactly you are looking for as far as output, but post here exactly how you want the output to look and Ill see what I can do. Use "dir" for directories (dir1 dir2 dir3) and "file" (file1 file2 file3) for files when exaplaining how you want it to look.
(ex.)
dir1
file1
file2
file3
dir2
file1
file2
file3

Hey,
Sorry about such an ambiguous request.
Anyway let me try to explain again.
Well basically I want to look at my files and directories(on my unix server(sunOs)) on an html page as a tree of some sorts.I have found a program on the web that does the exact thing I am looking for but I am not that experienced in writing scripts yet.
The website for the exact example I am looking at is:http://www.jpowered.com/applets/treemenu/Examples/ExampleDataFile.htm
and basically all the program does is look at the nodes.txt file and output the tree from that.
What each value means can be seen on this page:
http://www.jpowered.com/applets/treemenu/Documentation/page2.htm
Anyway I would greatly appreciate help with this.
Basically all I could think up was making a batch file I could run once a week or everymorning that included the command ls -R > file.txt and within that a read write type sort script that read that file and then created the nodes.txt which could be read when the website started up. Formating and reading the file is where I am stuck(sorry I'm pretty inexperienced).
Thanks for all your help,
Veneetps can email me and we can discuss further if preferred that way

Ok let me check it out for a little bit, this seems like it can be do able just may take a little time :)

This is a pain in the ass :)
I tried a for loop:
list=`ls -R | grep ":" | sed -e "s/\.//g" -e "s/://g"`
for var in $list;do
lfs=`echo $var | tr "[/]" "[.]"`
ls $var > filesfor$lfs
done
Thatll make a bunch of files in you directory called:
forfiles.directory.path
forfiles.directory.path.two
etcAnd in those files are the file lists for that directory.
*whew*
What needs to be done next is to read those files (probably using another for loop) and input it in the format that you need.
To get that stree structure you will need to perform a search for anything after the period (.) in the filename to get the directory it is in. Hope that gives you some soft of help/direction. Im at work now, but if I can find a little time Ill work on it a bit further.

hey thanks a lot for helping out.
Hmm I seem to be getting an error though running this to get the directories lower then the first level?
Reading it, well I'll try it...cannot gaurantee anything but lets see...Again thanks for your help.
Sincerely,
Veneetps What is your e-mail address? We can communicate through there then right?

Hmm no luck at all with reading....I figured out why it wasnt reading a step lower though...that might be because I had some directories that had a '.' in them themselves so...
Any more time for help=O)
Thanks,
Veneet

![]() |
how to parse a path in un...
|
important question..need ...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |