G
Guest
Hi, I’ve written a c# program to compact certain msaccess databases. The way
this works is to compact say C:\test1.mdb to C:\temp.mdb, then delete
C:\test1.mdb and rename C:\temp.mdb as C:\test1.mdb.
My problem occurs if there is already a C:\temp.mdb file. I don’t want to
just delete this, as it could have been created separately by a user.
In my code, I set a constant as follows:
private const string tempMdb = @"C:\temp.mdb";
To check that the file exists, I can use
if (File.Exists(tempMdb))...
but, if it is present, how do I change the tempMdb to a unique name?
I.e. if C:\temp.mdb is present, then rename as C:\temp1.mdb,
if C:\temp1.mdb is present, then rename as C:\temp2.mdb,
if C:\temp2.mdb is present, then rename as C:\temp3.mdb.....
I realise some sort of looping maybe required here but I’m not sure on the
best approach.
Thanks in advance.
this works is to compact say C:\test1.mdb to C:\temp.mdb, then delete
C:\test1.mdb and rename C:\temp.mdb as C:\test1.mdb.
My problem occurs if there is already a C:\temp.mdb file. I don’t want to
just delete this, as it could have been created separately by a user.
In my code, I set a constant as follows:
private const string tempMdb = @"C:\temp.mdb";
To check that the file exists, I can use
if (File.Exists(tempMdb))...
but, if it is present, how do I change the tempMdb to a unique name?
I.e. if C:\temp.mdb is present, then rename as C:\temp1.mdb,
if C:\temp1.mdb is present, then rename as C:\temp2.mdb,
if C:\temp2.mdb is present, then rename as C:\temp3.mdb.....
I realise some sort of looping maybe required here but I’m not sure on the
best approach.
Thanks in advance.