Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public static void CreateDirectoryInfo()
     {
         int RecordCountNew = 0;
         string DirectoryPath = @"E:\DattuFiles\";
         string filePath = string.Empty;
         DirectoryInfo directoryInfo = new DirectoryInfo(DirectoryPath);
         if (!directoryInfo.Exists)
         {
             directoryInfo.Create();
         }
         for (int i = 0; i < 10; i++)
         {
             if (RecordCountNew == i)
             {
                 filePath = Path.Combine(DirectoryPath, "Dattu" + i.ToString()+".txt");
             }
             if (filePath != "" && !File.Exists(filePath))
             {
                 File.Create(filePath).Dispose();
             }

             RecordCountNew = RecordCountNew++;

             if (!string.IsNullOrEmpty(filePath))
             {
                 File.AppendAllText(filePath, "this is eating my brain" + Environment.NewLine);
             }
         }
     }
Posted

1 solution

Run your code in the debugger and step through it to see what it's doing that you don't expect.

I think you will find that the statement RecordCountNew = RecordCountNew++; is not doing what you expect it to (even though it is doing exactly what you told it to do).

In fact, I don't see that the RecordCountNew variable is doing anything useful so I suggest you remove it entirely.
 
Share this answer
 
v2
Comments
viswadattu 10-Jan-16 0:17am    
But from the data base i will get the data as below format
like

1 dattu 1/1/2015
1 mike 1/1/2015

2 rocky 2/1/2015
2 sam 2/1/2015

based on these numbers files has to be created ie

Data with 1--> 1.txt
Data with 2--> 2.txt

hence i am using record count

Please help me

thanks in advance
Dave Kreskowiak 10-Jan-16 0:25am    
Put a Breakpoint on the first line of code in this method and step through the code line-by-line. Examin the variable contents along the way.

Really, you DAMN WELL BETTER LEARN to use the debugger. It'll WILL help you find the problem here and give you a better understanding of your own code in the process.

What's better? Constantly asking people to debug your code for you or learning to use the debugger and fixing the code yourself far more quickly?
PIEBALDconsult 10-Jan-16 0:29am    
Where's that upvote button... +5
Dave Kreskowiak 10-Jan-16 0:37am    
:)
viswadattu 10-Jan-16 0:33am    
ok thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900