Commit c84e38dcf62a150e4dc51a35923eb294a5458ee5

Authored by David René
1 parent 4edc98f1

add emptying_directory function

Showing 1 changed file with 32 additions and 2 deletions   Show diff stats
anubis_dev/library/system/files.anubis
... ... @@ -128,9 +128,9 @@ public define ResultCopy
128 128 }
129 129 }
130 130 else
131   - result
132   - .
  131 + result .
133 132  
  133 +
134 134 public define Bool
135 135 move_file
136 136 (
... ... @@ -351,3 +351,33 @@ public define Bool
351 351 false
352 352 }.
353 353  
  354 +define Bool
  355 + remove_files
  356 + (
  357 + String path,
  358 + List(String) files
  359 + )=
  360 + if files is
  361 + {
  362 + [] then true, //we have finished
  363 + [file_name . t ] then
  364 + if remove(path + file_name) then
  365 +// println("removing "+path+file_name);
  366 + remove_files(path, t)
  367 + else
  368 + println("can't remove file ["+path+file_name+"]"); false
  369 + }.
  370 +
  371 + /**
  372 + * Emptying directory, remove all files matching with the given mask
  373 + * If something wrong happend during the deletion of files the function
  374 + * may return false otherwise true
  375 + */
  376 +public define Bool
  377 + emptying_directory
  378 + (
  379 + String path,
  380 + String mask
  381 + )=
  382 + with path = normalize_path(path),
  383 + remove_files(path +"/", directory_list(path, mask)).
... ...