1
2
3
4
5
6 using System;
7 using System.Collections;
8 using System.IO;
9 using System.Os;
10 using paths;
11
12 void RemoveFiles(const List<string>& files, const List<FileType>& fileTypes, bool verbose, bool recursive)
13 {
14 long n = files.Count();
15 for (long i = 0; i < n; ++i;)
16 {
17 FileType fileType = fileTypes[i];
18 const string& path = files[i];
19 if (fileType == FileType.directory)
20 {
21 DirectoryReader reader(path);
22 DirectoryEntry entry;
23 List<string> filePaths;
24 while (reader.Read(entry))
25 {
26 if (entry.IsDot() || entry.IsDotDot())
27 {
28 continue;
29 }
30 string filePath = Path.Combine(path, entry.name);
31 filePaths.Add(filePath);
32 }
33 Remove(filePaths, verbose, recursive);
34 Directory.Remove(path);
35 if (verbose)
36 {
37 Console.Out() << path << " removed" << endl();
38 }
39 }
40 else if (fileType == FileType.regular)
41 {
42 File.Remove(path);
43 if (verbose)
44 {
45 Console.Out() << path << " removed" << endl();
46 }
47 }
48 else
49 {
50 throw FileSystemException("'" + path + "' not directory or regular");
51 }
52 }
53 }
54
55 void Remove(const List<string>& files, bool verbose, bool recursive)
56 {
57 List<FileType> fileTypes = GetFileTypes(files, recursive);
58 RemoveFiles(files, fileTypes, verbose, recursive);
59 }