• C

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

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 ?)

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.

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

how is the command 'ls' programmed :))
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
exit 0

that should do it.
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

SkAtAnAuthor Commented:
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
exit 0
[SkAtAn@frEAx dev]$
SkAtAnAuthor Commented:
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 :-)
i'll post it.
you can give me points even if i don't post it.
just click beside the comment you accept there is "accept comment as answer" or something like that
good luck in the future.


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

foreach file ( files )

insted of

foreach file ( $files )

and not as you wrote.
SkAtAnAuthor Commented:
Yes :) , I know .. woeps
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

From novice to tech pro — start learning today.