Link to home
Start Free TrialLog in
Avatar of SkAtAn
SkAtAn

asked on

finding files in a path (linux)

I wan't to write a program to make of all files
with the same name in 3 paths new files with
all the data of these files put into new (lol) files
in another path.. ahum :) , letme illustrate what
I mean :

I have for example
/path/topoffiles/this.file.contains.the.header.of.the.file.wich.will.be.generated
/path/middleoffiles/this.file.contains.the.middle.of.the.file.wich.will.be.generated
/path/endoffiles/this.file.contains.the.bottom.of.the.file.wich.will.be.generated
and
-->>
/path/newfiles/this.file.is.generated.with.3.files

I need this program/script for a website project
I am planning. to easily update the left/top/bottom
part of 'all' my html files (I don't want to use
frames so I will have to use panels at the left/top/bottom of each page)

Ok, so I guess I will have to write a program for
this :-) , I used to program in delphi/pascal until
I started with linux. But I want to make it in C
(so that I can use gcc , and start the program
on the http server if it's a unix/linux server)

I am planning to make this on my own, :) except if
somebody willing to help me (I am sure it's a tool
wich will be usefull for a lot webmasters, so I am
also planning to make it opensource, yea :)  who knows it will work someday man :))

The first part of the program is I guess, finding all
the files in /path , so each time It finds a file, it puts
it in a string (arrey of 255 chars eh, I know a little
bit c already :))  red books and stuff, but never
programmed a real app in c) .. and it calls a function
wich will generate /path/html/thefilename.html

Lol.. this first part is the part I don't find in any books, finding files in a path under linux in c,
I know it's with pascal with the findfirst/findnext
procedures.. but I don't know how in c :(

Also writing in TEXT files (wich html files are),
how do I do this.. (I already know how to do it
with pascal append/reset/write(T,string)/..
but how to do this in c ?)

freax
Avatar of SkAtAn
SkAtAn

ASKER

So actually .. what I need at this point
is :

how is the command 'ls' programmed :))
Avatar of ozo
man readdir
maybe you should use a unix script.
it's very easy task to do.

about this
-----------------------
#!/bin/csh -f

set TOP_DIR="/path/topoffiles"
set MID_DIR="/path/middleoffiles"
set BOT_DIR="/path/endoffiles"
set OUT_DIR="/path/newfiles"

set files=`ls $TOP_DIR`

foreach file ( files )
   cat $TOP_DIR/$file $MID_DIR/$file $BOT_DIR/$file > $OUT_DIR/$file
end
exit 0
------------------------

that should do it.
Avatar of SkAtAn

ASKER

There is a file named test.1 in each dir :

[SkAtAn@frEAx dev]$ ls
end.of.files  header.of.files  low.of.files  middle.of.files  new.files  script  top.of.files

[SkAtAn@frEAx dev]$ ./script
cat: ./header.of.files/files: No such file or directory
cat: ./top.of.files/files: No such file or directory
cat: ./middle.of.files/files: No such file or directory
cat: ./low.of.files/files: No such file or directory
cat: ./end.of.files/files: No such file or directory
[SkAtAn@frEAx dev]$

[SkAtAn@frEAx dev]$ pic script
..lf 1 script
#!/bin/csh -f

set HEA_DIR="./header.of.files"
set TOP_DIR="./top.of.files"
set MID_DIR="./middle.of.files"
set LOW_DIR="./low.of.files"
set BOT_DIR="./end.of.files"
set OUT_DIR="./new.files"

set files=`ls $HEA_DIR`

foreach file ( files )
cat $HEA_DIR/$file $TOP_DIR/$file $MID_DIR/$file $LOW_DIR/$file $BOT_DIR/$file > $OUT_DIR/$file
end
exit 0
[SkAtAn@frEAx dev]$
Avatar of SkAtAn

ASKER

OK, this is the thing you did wrong:
foreach file ( files )

had to be

foreach file ( files$1 )

np :) , post it as an answer and I'll give you
the points. thanx a lot :-)
ASKER CERTIFIED SOLUTION
Avatar of zulti
zulti

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
btw
i think the wrong thing was

foreach file ( files )

insted of

foreach file ( $files )

and not as you wrote.
Avatar of SkAtAn

ASKER

Yes :) , I know .. woeps