Created
August 16, 2012 22:12
-
-
Save ryanlane/3374093 to your computer and use it in GitHub Desktop.
Simple Command Line Numbered Folder Generator with C#
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
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace FolderMaker | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string path = Directory.GetCurrentDirectory(); | |
string start = ""; | |
string end = ""; | |
int startNum = 0; | |
int endNum = 0; | |
int howmanyZeros = 0; | |
if (args.Count() == 3) | |
{ | |
string cmdlinePath = args[0]; | |
start = args[1]; | |
end = args[2]; | |
if (System.IO.Directory.Exists(cmdlinePath)) | |
{ | |
path = cmdlinePath; | |
} | |
} | |
if (args.Count() == 2) | |
{ | |
start = args[0]; | |
end = args[1]; | |
} | |
int.TryParse(start, out startNum); | |
int.TryParse(end, out endNum); | |
if (args.Count() < 2) | |
{ | |
Console.WriteLine("example: xxxx <path> <start> <end>"); | |
Environment.Exit(0); | |
} | |
howmanyZeros = end.Length; | |
for (int i = startNum; i <= endNum; i++) | |
{ | |
// Create the subfolder | |
string magicZeros = getZero(howmanyZeros, i); | |
string newPath = System.IO.Path.Combine(path, magicZeros + i); | |
System.IO.Directory.CreateDirectory(newPath); | |
} | |
} | |
static string getZero(int zeros, int currentNumber) | |
{ | |
string newzeros = ""; | |
int numLength = currentNumber.ToString().Length; | |
int loopValue = zeros - numLength; | |
for (int i = 0; i < loopValue; i++) | |
{ | |
newzeros += "0"; | |
} | |
return newzeros; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment