Skip to content

Commit

Permalink
v1.2: Allow /p and /r options before or after main arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
nicjansma committed May 11, 2013
1 parent 826e891 commit e7b47ce
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Rename files in the pattern of "````124_xyz.txt````" to "````xyz_123.txt````":

* v1.0 - 2012-01-30: Initial release
* v1.1 - 2012-12-15: Added /r option
* v1.2 - 2013-05-11: Allow /p and /r options before or after main arguments

# Credits

Expand Down
Binary file modified bin/RR.exe
Binary file not shown.
42 changes: 29 additions & 13 deletions source/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// <copyright file="Program.cs" company="Nic Jansma">
// Copyright (c) Nic Jansma 2012 All Right Reserved
// Copyright (c) Nic Jansma 2013 All Right Reserved
// </copyright>
// <author>Nic Jansma</author>
// <email>nic@nicj.net</email>
Expand Down Expand Up @@ -53,7 +53,7 @@ public static int Main(string[] args)
// loop through each file, renaming via a regex
//
foreach (string fullFile in files)
{
{
// split into file and path
string fileName = Path.GetFileName(fullFile);
string fileDir = Path.GetDirectoryName(fullFile);
Expand Down Expand Up @@ -97,6 +97,7 @@ public static int Main(string[] args)
/// <param name="nameSearch">Search expression</param>
/// <param name="nameReplace">Replace expression</param>
/// <param name="pretend">Whether or not to only show what would happen</param>
/// <param name="recursive">Whether or not to recursively look in directories</param>
/// <returns>True if argument parsing was successful</returns>
private static bool GetArguments(
string[] args,
Expand All @@ -119,31 +120,46 @@ public static int Main(string[] args)
return false;
}

// set from arguments
fileMatch = args[0];
nameSearch = args[1];
nameReplace = args[2];
pretend = false;

//
// Optional arguments:
// Loop through all of the command line arguments.
//
// Look for options first:
// /p: pretend (show what will be renamed)
// /r: recursive
//
for (int i = 3; i < args.Length; i++)
// If not an option, assume it's one of the three main arguments (filename, search, replace)
//
for (int i = 0; i < args.Length; i++)
{
if (args[i].Equals("/p", StringComparison.OrdinalIgnoreCase))
{
pretend = true;
}

if (args[i].Equals("/r", StringComparison.OrdinalIgnoreCase))
else if (args[i].Equals("/r", StringComparison.OrdinalIgnoreCase))
{
recursive = true;
}
else
{
// if not an option, the rest of the arguments are filename, search, replace
if (String.IsNullOrEmpty(fileMatch))
{
fileMatch = args[i];
}
else if (String.IsNullOrEmpty(nameSearch))
{
nameSearch = args[i];
}
else if (String.IsNullOrEmpty(nameReplace))
{
nameReplace = args[i];
}
}
}

return true;
return !String.IsNullOrEmpty(fileMatch)
&& !String.IsNullOrEmpty(nameSearch)
&& !String.IsNullOrEmpty(nameReplace);
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// <copyright file="AssemblyInfo.cs" company="Nic Jansma">
// Copyright (c) Nic Jansma 2012 All Right Reserved
// Copyright (c) Nic Jansma 2013 All Right Reserved
// </copyright>
// <author>Nic Jansma</author>
// <email>nic@nicj.net</email>
Expand Down Expand Up @@ -35,7 +35,7 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]

[assembly:CLSCompliant(true)]
[assembly: CLSCompliant(true)]

0 comments on commit e7b47ce

Please sign in to comment.