kbalaraju
asked on
Changing name of a file.
I have some files in a folder with filename in format 123456.78j.
I would like to rename the corresponding file name to 12345678.jpg and I need to move it to a folder(Which is already existing with 2 digits after decimal point in filename(in this case 78)). I should do it with all the files existing in my input folder c:\input.
Can anyone help???
Thanks in Advance
-Raju
I would like to rename the corresponding file name to 12345678.jpg and I need to move it to a folder(Which is already existing with 2 digits after decimal point in filename(in this case 78)). I should do it with all the files existing in my input folder c:\input.
Can anyone help???
Thanks in Advance
-Raju
What O/S? Shell script or program?
standard C++ has no features for this.
You must use OS-specific or compiler-specific features for this. In windows you can use the MoveFile() function. Are you using windows?
You must use OS-specific or compiler-specific features for this. In windows you can use the MoveFile() function. Are you using windows?
ASKER
No. I'm using Unix and I have about 300 files in the folder. It would be fine, If it is a shellscript in Unix.
Thanks
Raju.
Thanks
Raju.
ASKER
You can give me the code in C/C++/Unix Shell script.
Thanks
Raju
Thanks
Raju
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
what if I want to move the file to parent directory/base2.
ex.
source file 98439.88j
mv the file to ../88/98439.jpg
What should I change in script file?
ex.
source file 98439.88j
mv the file to ../88/98439.jpg
What should I change in script file?
ASKER
what if I want to move the file to parent directory/base2.
ex.
source file 98439.88j
mv the file to ../88/98439.jpg
What should I change in script file?
ex.
source file 98439.88j
mv the file to ../88/98439.jpg
What should I change in script file?
ASKER
what if I want to move the file to parent directory/base2.
ex.
source file 98439.88j
mv the file to ../88/98439.jpg
What should I change in script file?
ex.
source file 98439.88j
mv the file to ../88/98439.jpg
What should I change in script file?
ASKER
what if I want to move the file to parent directory/base2.
ex.
source file 98439.88j
mv the file to ../88/98439.jpg
What should I change in script file?
ex.
source file 98439.88j
mv the file to ../88/98439.jpg
What should I change in script file?
echo "../"$base2"/"$base".jpg" > $new_name
ASKER
Adjusted points to 50
ASKER
I am still not clear about constructing mv command.
How do write mv in script ?
How do write mv in script ?
ASKER
I am still not clear about constructing mv command.
How do write mv in script ?
How do write mv in script ?
#! /bin/sh
for i in *
do
base=` echo $i | awk '{$foo=substr($0,1,length( $0)-4);pri nt $foo;}' `
base2=` echo $i | awk '{$foo=substr($0,length($0 )-2,2);pri nt $foo;}' `
new_name=`echo "../"$base2"/"$base".jpg"`
echo "moving " $i " to " $new_name
mv $i $new_name
done
Allthough Kernighan states that
echo $i > new_name
should work, it doesn't (not on every system at least). Therefore a small change in the construction of the new_name. This should work, sorry for the non working version :-)
for i in *
do
base=` echo $i | awk '{$foo=substr($0,1,length(
base2=` echo $i | awk '{$foo=substr($0,length($0
new_name=`echo "../"$base2"/"$base".jpg"`
echo "moving " $i " to " $new_name
mv $i $new_name
done
Allthough Kernighan states that
echo $i > new_name
should work, it doesn't (not on every system at least). Therefore a small change in the construction of the new_name. This should work, sorry for the non working version :-)