-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v1.2: Allow /p and /r options before or after main arguments
- Loading branch information
Showing
4 changed files
with
34 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>[email protected]</email> | ||
|
@@ -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); | ||
|
@@ -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, | ||
|
@@ -119,31 +120,46 @@ private static bool GetArguments( | |
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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>[email protected]</email> | ||
|
@@ -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)] |