Click here to Skip to main content
13,667,095 members
Click here to Skip to main content
Add your own
alternative version


49 bookmarked
Posted 8 Aug 2003
Licenced MIT

xmove - Regex enabled file move command

, 5 Nov 2003
Rate this:
Please Sign up or sign in to vote.
Moves files or directories using regular expression patterns.
<!-- Add the rest of your HTML here -->


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.
    Update : I dedicated a whole article to this class which you can view here.
  • 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.

Syntax :

xmove [options] [source root] <source regex pattern> [dest root] <dest regex pattern>

If [source root] is not specified, the current directory will be used.
If [dest root] is not specified, it will have the same value as [source root].

By default, xmove operates on any files but not on directories (/aF).

Options :

/batch=<filename> : Makes a batch file instead of moving immediately.

/case=<case option> : Changes the case of the destination filename as specified by option
  • lower : 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
You can specify more than one file attributes at the same time (e.g. /aacehnorst which is the same as /aF).

Examples :

  • Replaces all "_" characters by spaces in filenames :

    xmove "_" " "
  • Recursively changes case to "sentence" case for all files with "normal" and/or "archive" attributes :

    xmove /aan /r /case=sentence ".+" "$&"

Using the code

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.


  • 2003-08-20 : Fixed some minor bugs here and there.
  • 2003-08-26 : Completely rewrote ArgumentParser parsing class which was getting a bit convoluted.
  • 2003-08-26 : Forgot to allow empty arguments (which must be passed as "").
  • 2003-08-29 : Further enhanced ArgumentParser class with the idea of Ray Hayes in this article. I intend to publish this class in a new article.
  • 2003-08-30 : Improved performance of replace and corrected a bug preventing Ignore Case option to work.
  • 2003-08-31 : Added support for /arg=[false/true] or /arg=[0/1] (considered as switches)
  • 2003-09-01 : ArgumentParser class got his own article here.


This article, along with any associated source code and files, is licensed under The MIT License


About the Author

Sebastien Lorion
Canada Canada
Sébastien Lorion is software architect as day job.

He is also a musician, actually singing outside the shower Smile | :)

He needs constant mental and emotional stimulation, so all of this might change someday ...

You may also be interested in...

Comments and Discussions

Generaldon't understand moving without renaming [modified] Pin
duuekkk2-Apr-10 4:52
memberduuekkk2-Apr-10 4:52 
AnswerRe: don't understand moving without renaming Pin
Sebastien Lorion2-Apr-10 5:48
memberSebastien Lorion2-Apr-10 5:48 
GeneralSaved me an hour or two plus testing ;) Pin
patnsnaudy4-Jun-08 21:17
memberpatnsnaudy4-Jun-08 21:17 
AnswerRe: Saved me an hour or two plus testing ;) Pin
Sebastien Lorion4-Jun-08 21:27
memberSebastien Lorion4-Jun-08 21:27 
GeneralVery Close... Pin
Stryder13-Jul-06 12:22
memberStryder13-Jul-06 12:22 
AnswerRe: Very Close... Pin
Sébastien Lorion3-Jul-06 15:46
memberSébastien Lorion3-Jul-06 15:46 
GeneralThe Application Failed To Initialize Properly (0xc0000135) Pin
armega7-Feb-06 10:59
memberarmega7-Feb-06 10:59 
GeneralRe: The Application Failed To Initialize Properly (0xc0000135) Pin
Jerry Jeremiah25-Nov-07 21:45
memberJerry Jeremiah25-Nov-07 21:45 
GeneralOption to import batch list Pin
Jafin6-Dec-05 10:46
memberJafin6-Dec-05 10:46 
GeneralAdded ability to move files to a common directory Pin
pjbm10-Jul-05 16:52
memberpjbm10-Jul-05 16:52 
GeneralRe: Added ability to move files to a common directory Pin
Sébastien Lorion10-Jul-05 20:13
memberSébastien Lorion10-Jul-05 20:13 
GeneralAdded case change per matching groups Pin
johnhamm1-Jul-05 21:29
memberjohnhamm1-Jul-05 21:29 
GeneralRe: Added case change per matching groups Pin
Sébastien Lorion1-Jul-05 22:19
memberSébastien Lorion1-Jul-05 22:19 
Generali also give you 5 Pin
only_boby22-Jun-04 6:08
sussonly_boby22-Jun-04 6:08 
Generalnon-regex searches Pin
Kirk Hodges1-Jun-04 2:24
sussKirk Hodges1-Jun-04 2:24 
QuestionHow about a C++ version? Pin
Darren Schroeder31-Aug-03 15:27
memberDarren Schroeder31-Aug-03 15:27 
AnswerRe: How about a C++ version? Pin
Sébastien Lorion31-Aug-03 15:53
memberSébastien Lorion31-Aug-03 15:53 
GeneralRe: How about a C++ version? Pin
Darren Schroeder1-Sep-03 4:05
memberDarren Schroeder1-Sep-03 4:05 
GeneralTres bien fait - Felicitations! Pin
fbougadou13-Aug-03 6:30
memberfbougadou13-Aug-03 6:30 
GeneralRe: Tres bien fait - Felicitations! Pin
Sébastien Lorion13-Aug-03 12:32
memberSébastien Lorion13-Aug-03 12:32 
Generalgot my 5 Pin
Jonathan de Halleux9-Aug-03 2:38
memberJonathan de Halleux9-Aug-03 2:38 
GeneralRe: got my 5 Pin
Sébastien Lorion9-Aug-03 3:00
memberSébastien Lorion9-Aug-03 3:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04-2016 | 2.8.180810.1 | Last Updated 6 Nov 2003
Article Copyright 2003 by Sebastien Lorion
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid