This is how it was done using ruby
- #!/usr/bin/ruby
- dir = "/mnt/home/suresh"
- files = Dir.entries(dir)
- files.each do |f|
- next if f == "." or f == ".."
- if File.fnmatch('.*',f) then
- puts f
- newname = f + ".olddeb"
- File.rename(f,newname)
- end
- end
Line 5: To ignore the current and parent directories
LIne 6. I wanted to rename only files/directories starting with . (hidden files in unix)
Line 7. prints the current files - just for information
Line 8. the new name is old one with a .olddeb extension
Line 9. Does actual renaming
2 comments:
hello sir,,i dont know anything about ruby,this is how u can do this on python
//code starts here
import glob,shutil;
dir=glob.glob("/mnt/home/suresh/.*");
for content in dir:
shutil.move(content,content+".old")
//code ends here...thats all!!!!
glob function uses "." as a wild card and brings all names starting in it.It never brings "." and "..".The for loop goes through this list content and renames every file/directory starting with "." by appending ".old" to its end.
Hi Anonymous student,
I am slowly getting interested in python..I have one colleague who is a strong advocate...may be I would study python later....thanks for your comments
Post a Comment