![]() |
Languages »
C# »
Applications
Intermediate
License: The MIT License
xmove - Regex enabled file move commandBy Sebastien LorionMoves files or directories using regular expression patterns. |
C#, Windows, .NET 1.0, .NET 1.1VS.NET2003, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
Who haven't gone through the job of renaming a bunch of files ? I know I have for sure and up to this day, it was quite a chore ... Basically, I would fire up Textpad and make a batch file using its built-in Regular Expressions capabilities.
I did grow tired of always doing basically the same procedure over and over so I wrote this nifty utility in my spare time. You can think of it as the console "move" command on steroid, having all the power of regular expressions at its disposal.
With this tool, you can use a source Regex to specify which files to move/rename and then use any captures you made to specify the destination or new filenames.
This lets you easily rename all your mp3 in a standard way for example, or change the naming convention of a whole archive on your local intranet, etc.
It's up to you to provide the source and destination patterns : there are no built-in regex macros that you can use, except for changing case of filenames (to lower case, UPPER CASE, Proper Case and Sentence case), but it would be easy to add them if you feel so.
As a bonus, you will get two useful classes :
ArgumentParser : Full featured argument parsing class, supporting switches, name/value pairs, flags and solo values and implementing a cool idea thought out by Ray Hayes in this article.FindFile : File/directory searching class supporting both normal Regex and wildcard searches and using delegates to feed results Finally, every single line of text is put in a resource file so you can easily translate it in your language (mine is French, but I didn't bother to do it :p).
I STRONGLY encourage you to always use the /batch=filename option. Even if my code would be without defect (!), maybe your regex pattern has some ! Regular expressions are beasts not be handled carelessly ... Take my word for it :)
Should you find a bug or an annoyance or even a feature you would like, drop me a line and I will do my best. If you can do it, that's even better !
The following is the help displayed by default by the application.
xmove - Regex enabled move command by S�bastien Lorion, 2003
Moves files or directories using regular expression filters.
xmove [options] [source root] <source regex pattern> [dest root] <dest regex pattern>[source root] is not specified, the current directory will be used.[dest root] is not specified, it will have the same value as [source root]./aF)./batch=<filename> : Makes a batch file instead of moving immediately./case=<case option> : Changes the case of the destination filename as specified by optionlower : lower case
upper : UPPER CASE
proper : Proper Case
sentence: Sentence case /i : Ignores case/r : Operates recursively (if specified, you cannot move directories (excludes /aA and /ad options))/t : Test mode/yc : Suppresses confirmation of each move operation/yo : Suppresses confirmation of overwriting an existing file/a[A|F|a|c|d|e|h|n|o|r|s|t] : Limits move operation to files with specific attribute(s)A : Moves everything (including directories)
F : Moves any files
a : Moves only files with "archive" attribute
c : Moves only files with "compressed" attribute
d : Moves only files with "directory" attribute
e : Moves only files with "encrypted" attribute
h : Moves only files with "hidden" attribute
n : Moves only files with "normal" attribute
o : Moves only files with "offline" attribute
r : Moves only files with "read-only" attribute
s : Moves only files with "system" attribute
t : Moves only files with "temporary" attribute /aacehnorst which is the same as /aF).xmove "_" " "
xmove /aan /r /case=sentence ".+" "$&" There is no magic involved here nor some incredibly hard stuff, so the code should speak by itself :) It's well documented and is quite flowing, but feel free to ask questions if the need arise !
I dedicated a whole article to cover ArgumentParser class.
ArgumentParser parsing class which was getting a bit convoluted.
ArgumentParser class with the idea of Ray Hayes in this article. I intend to publish this class in a new article.
ArgumentParser class got his own article here.
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 5 Nov 2003 Editor: Nishant Sivakumar |
Copyright 2003 by Sebastien Lorion Everything else Copyright © CodeProject, 1999-2009 Web20 | Advertise on the Code Project |