Hi,
I have a directory structure like the one given below
root\a\b1
root\a\b2
root\b\b1
root\b\b2
.
.
.
root\j\b1
root\j\b2
Now, there are a txt files in each dir and subdir, there is a root.txt
I have to write a script where in i have to run a command called "genrb <filename>" on each of these txt files.
Please help me.
clx
September 2, 2009, 6:34am
2
windows or unix? (backslash confused me)
for file in $(find $starting_path -name "root.txt" -type f)
do
echo $file ## any command you want to run with each txt file
done
Hi
The command that i have to run has to run when the working directory is where the txt is.
So, a script which traverses through a dir structure and runs the command whenever it finds a .txt would help.
clx
September 2, 2009, 7:51am
4
try soemthing like :
for file in $(find $starting_path -name "root.txt" -type f)
do
FILE=$(basename $file)
DIR=$(dirname $file)
cd $DIR
echo $FILE ## any command you want to run with each txt file
done
Thanks a lot. It is working fine now.
One last query.
How can i pass a windows folder path as a param.
this is my func
for file in $(find c:\\temp\\ -name "root.txt" -type f)
do
genrb.exe $file -d $(dirname $file)
done
and i run it as
C:\temp2>script.sh
now i want to pass the path i.e. c:\temp as a parameter.
clx
September 7, 2009, 7:03am
6
since you are using MKS, I am not sure about it as I never worked on it.
but i think the paths will be understood by MKS automatically.( not sure)
other people can help better in this case.
i was thinking of something like this:
proc main{argv argc}
{
set path [lindex $argv 0]
for file in $(find $path -name "root.txt" -type f)
do
genrb.exe $file -d $(dirname $file)
done
}
main $argv $argc
and i run it as
C:\temp2>script.sh C:\temp\
Logicaly this should work
But this is still giving an error