crest Posted March 8, 2008 Share Posted March 8, 2008 (edited) What i want to do is to rename files like this:Original: movie.s03e02.temp.(34sd8fds).2asdlkha.aviNew: movie - s03e02.aviSo basically i want to remove everything after the second dotTo do this i tried to match it against a regexp and then use the matched pattern to build a new filename.In the code below im testing, if the filename matches against the pattern.$FileList = _FileListToArray($path, "*.avi") For $i=1 To UBound($FileList)-1 $oldName = StringStripWS($FileList[$i], 4) $newName = StringRegExp ($oldName, "(^\.+\.){2}", 0) ToolTip($oldName & " - " & $newName) Sleep(5000) NextThe Regexp (^\.+\.){2}should match 1-unlimited characters that are not "dots"and then the next character should be a single dot.This whole pattern repeated exact 2 times.At least, thats what i want it to do. Yet it doesnt seem to be the right syntaxGiven that the aviname is movie.s03e02.temp.(34sd8fds).2asdlkha.avithe tooltip should then display 1. But it doesnt.Ive been reading the helpfile and documentation, yet i cant figure out why my regexp doesnt match.I'd be grateful for an explanation why this doesnt work and what i could do to change it Edited March 8, 2008 by crest Link to comment Share on other sites More sharing options...
weaponx Posted March 8, 2008 Share Posted March 8, 2008 (edited) #include <Array.au3> $string = "movie.s03e02.temp.(34sd8fds).2asdlkha.avi" ;REGEX $result = StringRegExp($string,"(.+)\.(.+)\.(?:.+)\.\((?:.+)\)\.(?:.+)",3) $newString = StringFormat("%s-%s",$result[0],$result[1]) MsgBox(0,"",$newString) ;STRINGSPLIT $result = StringSplit($string, ".") $newString = StringFormat("%s-%s",$result[1],$result[2]) MsgBox(0,"",$newString) By the way, the ^ symbol matches everything NOT in the group. Edited March 8, 2008 by weaponx Link to comment Share on other sites More sharing options...
crest Posted March 8, 2008 Author Share Posted March 8, 2008 (edited) ive tried the splitstring variant earlier on (since you posted a similar one in my other thread)and it worked quite well, but i just had one problem. if you let the program run a second time, then all files that had been altered already would be altered again. And their name would get messes up, because there was only a single dot and not multiple ones.the other vairiant that you posted seems to work ... i just have to figure out what the regexp actually does.Regarding that: i thought that "(.+)\." shouldnt work, since in the .+ the normal dots are also incuded, so it would match the whole string.Then it actually should never reach the escaped dots \. in the regexp.So why does it work?EDIT: if i get this right, everything after (.+)\.(.+)\. in your regexp is only "optional", as it would only handle the stuff after the second dot?After testing the whole regexp you provided, i noticed that it seems to work only on files that have excatly (or at least) 4 dots in the name.Well, i didnt think that you would take the example aviname that literally, since i actually wanted to get rid of the junk after the second dot.So if there was another file with only 4 dots (3 + fileextension) in the filename, like movie.s03e02.temp.(34sd8fds).avi or even like this: movie.s03e02.temp.aviThe program wont work.Im sorry about that, that i wasnt detailed/accurate enough.So, what i wanted my program to do is to rename a file consistent of an arbitrary amount of substrings separated by dots,into a file that only uses the first 2 substrings (= get rid of everything behind the second dot)And the substrings dont have to look exactly like the one i posted aboveThe parenthesis were just an example. It could have looked like this as well: movie.s03e02.aF3](.d9wl3.ffff22()().2asdlkha.aviI just wanted to notify that there might be special signs in the string, and not only numbers and letters. Edited March 8, 2008 by crest Link to comment Share on other sites More sharing options...
weaponx Posted March 8, 2008 Share Posted March 8, 2008 I would just use StringSplit() and do a check on element zero to make sure the number of elements is greater than a certain amount. This will let you know which files had already been converted. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now