You mean you have a lot of files named 019287309128Kdsj21 and you want them renamed from 1 to (number of files)?
I'm having one problem.
I was testing out KMail's newly supported "maildir" format mail boxes but decided that I'm more into Sylpheed's MH mail boxes style especally since Sylpheed support importing from mbox style with ease. Kmail create directory with long file names such as 1036119107.1941.eTnT:2,S which Sylpheed could not understand even though I moved mail messages to Sylpheed's inbox folder and rescan it. Sylpheed puts messages in files names such as 1, 2, 3 and so on.
As a test, I rename the Kmail's long file name from 1036119107.1941.eTnT:2,S to the short format 1 and Sylpheed reads it good, no problem.
Now the problem is if I have to rename all the mails, I will have to do it 11728 times ( since I have a lot of mailing lists stuff which I like to migrate and preserve it ) and it's this huge task of doing it.
So can I use the scripts ( I know nothing about scripting ) for this stuff? Either with sed or awk or bash or whatever?? For example, read the file name in this specific folder, if the file name is longer than 8 charactors, then rename it to whichever file names that is one more incremental from the previous renaming? May be with C or C++ program?
Please help.
TIA
You mean you have a lot of files named 019287309128Kdsj21 and you want them renamed from 1 to (number of files)?
This will change all names in the current directory to normal number (ie: 000000001 becomes 1, 000000234 becomes 2, etc ...). Run it on a test set to make sure it's what you need.
Code:#!/bin/bash TMPVAR=1 for i in *; do if [ $i != 'test.sh' ]; then mv $i $TMPVAR; TMPVAR=$[TMPVAR + 1]; fi done
[quote author=GnuVince link=board=9;threadid=5504;start=0#53029 date=1036345435]
You mean you have a lot of files named 019287309128Kdsj21 and you want them renamed from 1 to (number of files)?
[/quote]
Actually, the names are different ( I think it's how KMail's identify mail messages ). So, one message is 123456789.123456.ijKl,S;2 and another is 123456789.123456.ikJE,s;2 and so on. So the difference is only ijKl and ikJE part of it.
I wanted to rename the first file names which are longer than 8 characters to 1 and then the second file names which are longer than 8 characters to 2 and the next file names which are longer than 8 characters to 3 and so on. So that Sylpheed will read the messages but renaming will not over ride messages ( if the name is the same such as 1, then only the last file will be able to read it, right? )
Do I make any sense?
Thanks.
[quote author=Ashcrow link=board=9;threadid=5504;start=0#53076 date=1036376525]
This will change all names in the current directory to normal number (ie: 000000001 becomes 1, 000000234 becomes 2, etc ...). Run it on a test set to make sure it's what you need.
[/quote]
Yeah, thanks. I will try it out.
[quote author=Ashcrow link=board=9;threadid=5504;start=0#53076 date=1036376525]
This will change all names in the current directory to normal number (ie: 000000001 becomes 1, 000000234 becomes 2, etc ...). Run it on a test set to make sure it's what you need.
[/quote]
I tested and it's not exactly what I needed.
I moved about 10 mails and run the script. It replace all 10 mails with only one file, 1. It wiped the 9 mails that I needed to preserve.
May be I need some kind of loop thing?? Currently, it's replacing ALL files eith only one file.Code:#!/bin/bash TMPVAR=1 for i in *; do if [ $i != 'test.sh' ]; then mv $i $TMPVAR; TMPVAR=$[TMPVAR + 1]; fi done
Please help. :'(
I know this is a long shot, but how about something like:
It will assure, the $TMPVAR is climbing, but if you reach MAX_LENGTH of assignment for the $TMPCNT it will start from 0 again.Code:#!/bin/bash TMPVAR=0 TMPCNT="" for i in *; do if [ $i != 'test.sh' ]; then TMPVAR=`echo $TMPCNT | wc -c` mv $i $TMPVAR; TMPCNT=".$TMPCNT" fi done
I know there is a clever way, but I just can't remember right now.. It has something todo with a 'set' or 'assign' like keyword, the $TMPVAR should be initialized with, else it can't be used as a counter.
Fixed scriptCode:#!/usr/bin/env ruby if ARGV.length != 1 puts "Usage: #$0 <directory>" exit 1 end my_dir = ARGV[0] current_email = 1 Dir.chdir(my_dir) Dir.foreach(".") { |file| File.rename(file, current_email.to_s) current_email += 1 } puts "Done."
GnuVince,
Since I know nothing about programming ....
All I do is update <directory> part of it and install ruby to run it??
TIA
Bookmarks