473,396 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

C#: generating random files

Hi All,

Can anyone help me with a method that could generate random dummy files with extensions..(.txt, .log, .exe) in a specified folder?
Dec 17 '07 #1
3 2626
Plater
7,872 Expert 4TB
Just make a series of them?
for (int i=0; i< (some number); i++)
{
string filename="dummyfile"+i.ToString()+".log";
//Create/populate file as needed
}
Dec 17 '07 #2
How do i use the following code to create files with different filter?

Expand|Select|Wrap|Line Numbers
  1.         private void button1_Click(object sender, EventArgs e)
  2.         {
  3.             StreamWriter outStream = null;
  4.             string filename = "output.txt";
  5.             string message = null;
  6.  
  7.             for (int i = 0; i < (1000); i++)
  8.             {
  9.                 try
  10.                 {
  11.                     outStream = new StreamWriter(filename);
  12.                     outStream.WriteLine("Hello World");
  13.                     outStream.Close();
  14.                     MessageBox.Show(filename);
  15.                 }
  16.                 catch (IOException e1)
  17.                 {
  18.                     message = "Unable to create " + filename + "\r\n";
  19.                     message += String.Format("Reason: {0}", e1.Message);
  20.                     MessageBox.Show(message);
  21.                 }
  22.                 message = ("File successfully created");
  23.             }
  24.  
Dec 17 '07 #3
Plater
7,872 Expert 4TB
You're only making one file there. (just doing it 1000 times)

You could switch it around the value of i maybe?
Expand|Select|Wrap|Line Numbers
  1. string filename="output";
  2. filename+=i.ToString();
  3. if (i%3==0)
  4. {//multiple of three
  5. filename+=".txt";
  6. }
  7. else if(i%5==0)
  8. {//multiple of 5
  9. filename+=".log";
  10. }
  11. else
  12. {
  13. filename+=".dat";
  14. }
  15.  
Dec 17 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: eric.gagnon | last post by:
In a program randomly generating 10 000 000 alphanumeric codes of 16 characters in length (Ex.: "ZAZAZAZAZAZAZ156"), what would be an efficient way to ensure that I do not generate duplicates? ...
1
by: Intaek LIM | last post by:
generally, we use srand(time(0)) to generate random numbers. i know why we use time(0), but i can not explain how it operates. first, see example source below. ...
3
by: FredC | last post by:
After approximately 90000 calls to the Random.Next(iLowerBound, iUpperBound) this function stops generating random numbers and returns iLowerBound. Is this just me or is this a known problem?
2
by: Joe | last post by:
Hi, I am building web in ASP.NET using VB.NET to code the pages. I want to generate random passwords for users. I know that password hashing is built right into the .NET Framework. I was...
6
by: Intiha | last post by:
Hello all, I am trying to generate random seeds for my simulations. currently i was using srand(time(NULL); for this purpose. But for confidence in my results i ran it using a script in a loop....
2
by: Simon Wittber | last post by:
I'm building a web application using sqlalchemy in my db layer. Some of the tables require single integer primary keys which might be exposed in some parts of the web interface. If users can...
2
by: randomcz | last post by:
hi, i need help with generating random numbers; The task is to generate hundreds of random vectors, like 1,3,5,6,7 2,4,5,4,8 ... I used the current time as the random seed, but it turns...
1
by: Velhari | last post by:
Hi, I am a beginner. Please tell me, For generating Random Numbers, Initially why we are going for seed method. And another question is that, I want to print unique random number how to print by...
0
SammyB
by: SammyB | last post by:
These are some "random" thoughts about generating random numbers in Visual Basic. Wikipedia will give a better introduction than I, see http://en.wikipedia.org/wiki/Random_number_generator. ...
26
by: bilgekhan | last post by:
What is the correct method for generating 2 independent random numbers? They will be compared whether they are equal. What about this method: srand(time(0)); int r1 = rand(); srand(rand());...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.