Hi All,
I have an interesting problem, I need to create save files in the following format SV_XXXX.msg in a specified location. This I am doing I have a folder with SV_0000.msg to SV_0132.msg
however it will not create SV_0133.msg onwards, it just appears to over write SV_0132.msg with the last data. Is there a reason for this or do I have to rework the way I am calculating the number?
Glenn
Loading

VulpesRank #55 · 29.2K reputationPosted Aug 29, 2012, 5:40 AM EDT
Suthish NairRank #92 · 22.8K reputationPosted Aug 28, 2012, 5:53 AM EDT
Glenn PattonRank #6,159 · 275 reputationPosted Aug 28, 2012, 6:02 AM EDT
EDIT
=-=-=-=-=-=-=-=-=-=-=-=-=
It seems it is not a problem other than the directory it is supposed to be!!!
Glenn PattonRank #6,159 · 275 reputationPosted Aug 28, 2012, 6:02 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 28, 2012, 6:31 AM EDT
Years ago, there used to be a limit on the number of files you could have in a root drive under Windows. I'm not sure whether there's a limit now or not, but even if there is I'm sure the OS wouldn't just overwrite an existing file.
Glenn PattonRank #6,159 · 275 reputationPosted Aug 28, 2012, 7:03 AM EDT
Glenn
VulpesRank #55 · 29.2K reputationPosted Aug 28, 2012, 7:31 AM EDT
copy con SV_0216.msg
^Z
To type ^Z, press the Z key while holding down the Ctrl key.
If that succeeds in creating an empty file, then you'll know that the problem lies with your code rather than the OS.
Glenn PattonRank #6,159 · 275 reputationPosted Aug 28, 2012, 7:51 AM EDT
Yup my code is causing the problem (suprise, suprise).
Glenn PattonRank #6,159 · 275 reputationPosted Aug 29, 2012, 12:36 AM EDT
Glenn
VulpesRank #55 · 29.2K reputationPosted Aug 29, 2012, 1:17 AM EDT
Glenn PattonRank #6,159 · 275 reputationPosted Aug 29, 2012, 1:29 AM EDT
string[] file_Next = Directory.GetFiles(@mydocpath, "*.msg");
int FileTotal = 0;
and once the file data has been set up
StreamWriter sw = new StreamWriter(mydocpath + @"\SV_" + FileNameRecord + ".msg");
dt.ToString("yyyy/MM/dd HH:mm:ss");
FileNameRecord = (FileIDFiller + FileCounter.ToString());
//StreamWriter sw = new StreamWriter(mydocpath + @"\SV_" + FileNameRecord + ".msg");
sw.WriteLine("Test " + FileCounter.ToString()+" "+dt.ToString());
sw.WriteLine(Unit_Reply_Modded);
FileCounter++;
strFileCount = Convert.ToString(FileCounter); ;
sw.Close();
Could something here be causing the problem....
Glenn
VulpesRank #55 · 29.2K reputationPosted Aug 29, 2012, 1:37 AM EDT
If there are any other files (not fitting your pattern) which have a .msg extension, then they may be being counted.
If there are omissions in the sequence of files fitting your pattern (say sv_0130 is missing), then this will also mess up the counting.
So how are you calculating FileCounter?
If you're just using file_Next.Length, then this might be causing the problem.
Glenn PattonRank #6,159 · 275 reputationPosted Aug 29, 2012, 2:02 AM EDT
Glenn
VulpesRank #55 · 29.2K reputationPosted Aug 29, 2012, 2:22 AM EDT
Glenn PattonRank #6,159 · 275 reputationPosted Aug 29, 2012, 2:26 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 29, 2012, 2:32 AM EDT
Glenn PattonRank #6,159 · 275 reputationPosted Aug 29, 2012, 2:44 AM EDT
VulpesRank #55 · 29.2K reputationPosted Aug 29, 2012, 3:05 AM EDT
Glenn PattonRank #6,159 · 275 reputationPosted Aug 29, 2012, 3:08 AM EDT
-=-=-=-=-=-=-=-=-=-=-=-=-
This seems to have righted it self
VulpesRank #55 · 29.2K reputationPosted Aug 29, 2012, 3:29 AM EDT
If this is happening with the next file to be saved after retrieving the maximum existing file, have you remembered to increase FileCounter by one?
Glenn PattonRank #6,159 · 275 reputationPosted Aug 29, 2012, 3:52 AM EDT
sw.WriteLine(Unit_Reply_Modded);
FileCounter++;
strFileCount = Convert.ToString(FileCounter); ;
sw.Close();
As this is in a click routine might it not being seen/skipping it?
VulpesRank #55 · 29.2K reputationPosted Aug 29, 2012, 4:04 AM EDT
I'd try placing this line immediately after the LINQ code:
FileCounter++;
Glenn PattonRank #6,159 · 275 reputationPosted Aug 29, 2012, 4:09 AM EDT
Glenn PattonRank #6,159 · 275 reputationPosted Aug 29, 2012, 5:28 AM EDT
if(string[] file_Next = Directory.GetFiles(@mydocpath, "*.msg") == Null)
{
file_Next = SV_0000.msg;
/* or null to avoid there never being a 0000 */
}
followed by
string[] file_Next = Directory.GetFiles(@mydocpath, "SV_????.msg");
However this problem aside it appears to have cured the issue (at the moment)
Glenn
Glenn PattonRank #6,159 · 275 reputationPosted Aug 29, 2012, 5:49 AM EDT