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.fi le.wich.wi ll.be.gene rated
/path/middleoffiles/this.f ile.contai ns.the.mid dle.of.the .file.wich .will.be.g enerated
/path/endoffiles/this.file .contains. the.bottom .of.the.fi le.wich.wi ll.be.gene rated
and
-->>
/path/newfiles/this.file.i s.generate d.with.3.f iles
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.htm l
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,strin g)/..
but how to do this in c ?)
freax
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
/path/middleoffiles/this.f
/path/endoffiles/this.file
and
-->>
/path/newfiles/this.file.i
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.htm
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,strin
but how to do this in c ?)
freax
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/middleoffil es"
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.
it's very easy task to do.
about this
-----------------------
#!/bin/csh -f
set TOP_DIR="/path/topoffiles"
set MID_DIR="/path/middleoffil
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.
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]$
[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]$
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 :-)
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
btw
i think the wrong thing was
foreach file ( files )
insted of
foreach file ( $files )
and not as you wrote.
i think the wrong thing was
foreach file ( files )
insted of
foreach file ( $files )
and not as you wrote.
ASKER
Yes :) , I know .. woeps
ASKER
is :
how is the command 'ls' programmed :))