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
kbalarajuAsked:
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.

snifongCommented:
What O/S?  Shell script or program?
0
nietodCommented:
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?
0
kbalarajuAuthor Commented:
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.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

kbalarajuAuthor Commented:
You can give me the code in C/C++/Unix Shell script.
Thanks
Raju
0
wytzeCommented:
#! /bin/sh
for i in *
do
      echo $i
      base=` echo $i |  awk '{$foo=substr($0,1,length($0)-4);print $foo;}' `
      base2=` echo $i |  awk '{$foo=substr($0,length($0)-2,2);print $foo;}' `
      echo $base2"/"$base$base2".jpg" > $new_name
      echo $new_name
      # create the move command
      # something like: mv $i $new_name
      # i cannot test this without any dir struc
done
0

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
kbalarajuAuthor Commented:
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?
0
kbalarajuAuthor Commented:
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?
0
kbalarajuAuthor Commented:
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?
0
kbalarajuAuthor Commented:
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?
0
wytzeCommented:
echo "../"$base2"/"$base".jpg" > $new_name
0
kbalarajuAuthor Commented:
Adjusted points to 50
0
kbalarajuAuthor Commented:
I am still not clear about constructing mv command.
How do write mv in script ?
0
kbalarajuAuthor Commented:
I am still not clear about constructing mv command.
How do write mv in script ?
0
wytzeCommented:
#! /bin/sh
for i in *
do
      base=` echo $i |  awk '{$foo=substr($0,1,length($0)-4);print $foo;}' `
      base2=` echo $i |  awk '{$foo=substr($0,length($0)-2,2);print $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 :-)
0
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
C++

From novice to tech pro — start learning today.