--- posUpdate/posUpdate/Util.cs 2013/03/21 10:40:24 710
+++ xmlTools/trunk/posUpdate/Util.cs 2013/03/26 15:04:38 745
@@ -18,15 +18,15 @@ namespace xmlTools
///
static public bool backupFile(string file)
{
- //try
- //{
- // System.IO.File.Copy(file, file + ".bak", false); //make a backup first //false is to not override already created backups
- //}
- //catch (Exception e)
- //{
- // Program.printAppError(Program.appErrors.BACKUPS_ALREADY_EXISTS, "Couldn't backup file " + file + " :\n" + e.Message);
- // return false;
- //}
+ try
+ {
+ System.IO.File.Copy(file, file + ".bak", false); //make a backup first //false is to not override already created backups
+ }
+ catch (Exception e)
+ {
+ Program.printAppError(Program.appErrors.BACKUPS_ALREADY_EXISTS, "Couldn't backup file " + file + " :\n" + e.Message);
+ return false;
+ }
return true;
}
@@ -86,11 +86,18 @@ namespace xmlTools
public static List getXmlFilesWildcard(String filewildcard)
{
List xmlFiles = new List();
- String[] files = System.IO.Directory.GetFiles(getExePath()); //Get all files in executable directory
+
+ String dir = Path.GetDirectoryName(filewildcard); // Get the specified directory
+ if (dir == "")
+ {
+ dir = Util.getExePath();
+ }
+ String wildcard = Path.GetFileName(filewildcard); // Get files/wildcard
+ String[] files = System.IO.Directory.GetFiles(dir); //Get all files in specified directory
foreach (String file in files)
{
- Regex wildcardRegex = new Regex(Util.WildcardToRegex(filewildcard), RegexOptions.IgnoreCase); //case insensitivity
+ Regex wildcardRegex = new Regex(Util.WildcardToRegex(wildcard), RegexOptions.IgnoreCase); //case insensitivity
if (wildcardRegex.IsMatch(Path.GetFileName(file)))
{
xmlFiles.Add(file);
@@ -136,5 +143,22 @@ namespace xmlTools
{
return Type.GetType("Mono.Runtime") != null;
}
+
+ public static bool ContainsIgnoreCase(string source, string sToSearch)
+ {
+ return source.IndexOf(sToSearch, StringComparison.OrdinalIgnoreCase) >= 0;
+ }
+
+ // Thanks DarthDevilous for the regex! http://forums.thedailywtf.com/forums/t/2478.aspx
+ public static string[] stringToArgsArray(string args)
+ {
+ MatchCollection ms = Regex.Matches(args, "([^\" ]*(\"[^\"]*\")[^\" ]*)|[^\" ]+");
+ List listArgs=new List();
+ foreach (Match m in ms)
+ {
+ listArgs.Add(m.Value.Replace("\"","")); //remove quotes or it will cause an error
+ }
+ return listArgs.ToArray();
+ }
}
}