Created
June 4, 2012 11:21
-
-
Save slideep/2867812 to your computer and use it in GitHub Desktop.
Quickly generate random data files (with extension from pre-defined list).
This file contains hidden or 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
| private static void GenerateRandomDataFiles(int countOfDataFiles) | |
| { | |
| if (countOfDataFiles <= 0) | |
| { | |
| throw new ArgumentOutOfRangeException("countOfDataFiles", "Expected at least a positive numeric value."); | |
| } | |
| Enumerable.Range(0, countOfDataFiles).ToList().ForEach(i => | |
| { | |
| const string foobarPrefix = "foobar"; | |
| // content | |
| var foobarText = new Random((int)TimeSpan.MaxValue.Ticks).Next() + Guid.NewGuid().ToString(); | |
| // random file extension index | |
| var nextIndex = NextIndexRandom.Next(0, Extensions.Count); | |
| var randomDataFilePath = Path.Combine(Path.GetTempPath(), foobarPrefix); | |
| var randomDataFileName = string.Format("{0}-{1}{2}",foobarPrefix, i, Extensions[nextIndex]); | |
| var randomDataFileFullPath = Path.Combine(randomDataFilePath, randomDataFileName); | |
| if (!Directory.Exists(randomDataFilePath)) | |
| Directory.CreateDirectory(randomDataFilePath); | |
| File.WriteAllText(randomDataFileFullPath, foobarText); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment