[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

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

  • 4
  • 3
1 Solution
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.
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

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.

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

Featured Post

KuppingerCole Reviews AlgoSec in Executive Report

Leading analyst firm, KuppingerCole reviews AlgoSec's Security Policy Management Solution, and the security challenges faced by companies today in their Executive View report.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now