Register
It is currently Tue Sep 23, 2014 8:23 pm

Simple script request


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Tue May 17, 2005 11:22 am   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 667
Location: Des Moines, Iowa
Originally posted by detra83
Hi,

here's my request. I would need a script that adds ".old" after all files in current directory. Example:
Directory contains:
- test.txt
- archive.zip
- pic.jpg

After the script, the files should look something like this:
- test.txt.old
- archive.zip.old
- pic.jpg.old

The reverse should also be possible; if you have test.txt.old, the script should convert it back to test.txt.

If anyone has any idea or tips on solving this, please let me know. If there's a script like this already somewhere, please let me know also.

I can offer help in C++ and/or MFC in return for your help.

Thanks

Deno


Top
 Profile WWW  
 PostPosted: Tue May 17, 2005 8:04 pm   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
hi Deno..

providing you are in the directory you want to edit the filenames (in current directory)
you could do it with a simple loop

Code:
#!/bin/bash

for file in *
do     
            if [[ ${file:${#file}-4:4} = ".old" ]]
            then
                   # getting rid of the .old extension
                   mv "${file}" "${file:0:${#file}-4}"
            else
                   # adding the .old extension
                   mv "${file}" "${file}.old"
            fi
done

hope that helps you out :)


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP