@@ -68,6 +68,11 @@ private FileInfo getOldestFileInDir(DirectoryInfo dir)
68
68
return dir . GetFiles ( ) . OrderByDescending ( f => f . LastWriteTime ) . Last ( ) ;
69
69
}
70
70
71
+ public bool IsDirectoryEmpty ( string path )
72
+ {
73
+ return ! Directory . EnumerateFileSystemEntries ( path ) . Any ( ) ;
74
+ }
75
+
71
76
72
77
private void Form1_Load ( object sender , EventArgs e )
73
78
{
@@ -195,7 +200,14 @@ public void doBackup(object sender, EventArgs e)
195
200
if ( ! Directory . Exists ( ds1destination ) )
196
201
Directory . CreateDirectory ( ds1destination ) ;
197
202
198
- if ( PraiseTheSave . Properties . Settings . Default . LastDS1Change != File . GetLastWriteTime ( getLatestFileInDir ( new DirectoryInfo ( ds1save ) ) . FullName ) )
203
+ DateTime ? lastDS1Change = PraiseTheSave . Properties . Settings . Default . LastDS1Change ;
204
+ if (
205
+ IsDirectoryEmpty ( ds1destination )
206
+ ||
207
+ ! lastDS1Change . HasValue
208
+ ||
209
+ PraiseTheSave . Properties . Settings . Default . LastDS1Change != File . GetLastWriteTime ( getLatestFileInDir ( new DirectoryInfo ( ds1save ) ) . FullName )
210
+ )
199
211
{
200
212
while ( PraiseTheSave . Properties . Settings . Default . SaveAmount <= Directory . GetFiles ( ds1destination ) . Length )
201
213
{
@@ -220,7 +232,14 @@ public void doBackup(object sender, EventArgs e)
220
232
if ( ! Directory . Exists ( ds2destination ) )
221
233
Directory . CreateDirectory ( ds2destination ) ;
222
234
223
- if ( PraiseTheSave . Properties . Settings . Default . LastDS2Change != File . GetLastWriteTime ( getLatestFileInDir ( new DirectoryInfo ( ds2save ) ) . FullName ) )
235
+ DateTime ? lastDS2Change = PraiseTheSave . Properties . Settings . Default . LastDS2Change ;
236
+ if (
237
+ IsDirectoryEmpty ( ds2destination )
238
+ ||
239
+ ! lastDS2Change . HasValue
240
+ ||
241
+ PraiseTheSave . Properties . Settings . Default . LastDS2Change != File . GetLastWriteTime ( getLatestFileInDir ( new DirectoryInfo ( ds2save ) ) . FullName )
242
+ )
224
243
{
225
244
226
245
while ( PraiseTheSave . Properties . Settings . Default . SaveAmount <= Directory . GetFiles ( ds2destination ) . Length )
@@ -246,7 +265,14 @@ public void doBackup(object sender, EventArgs e)
246
265
if ( ! Directory . Exists ( ds3destination ) )
247
266
Directory . CreateDirectory ( ds3destination ) ;
248
267
249
- if ( PraiseTheSave . Properties . Settings . Default . LastDS3Change != File . GetLastWriteTime ( getLatestFileInDir ( new DirectoryInfo ( ds3save ) ) . FullName ) )
268
+ DateTime ? lastDS3Change = PraiseTheSave . Properties . Settings . Default . LastDS3Change ;
269
+ if (
270
+ IsDirectoryEmpty ( ds3destination )
271
+ ||
272
+ ! lastDS3Change . HasValue
273
+ ||
274
+ PraiseTheSave . Properties . Settings . Default . LastDS3Change != File . GetLastWriteTime ( getLatestFileInDir ( new DirectoryInfo ( ds3save ) ) . FullName )
275
+ )
250
276
{
251
277
252
278
while ( PraiseTheSave . Properties . Settings . Default . SaveAmount <= Directory . GetFiles ( ds3destination ) . Length )
0 commit comments