1 // =================================
 2 // Copyright (c) 2022 Seppo Laakko
 3 // Distributed under the MIT license
 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>& filesconst List<FileType>& fileTypesbool verbosebool 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(pathentry.name);
31                 filePaths.Add(filePath);
32             }
33             Remove(filePathsverboserecursive);
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>& filesbool verbosebool recursive)
56 {
57     List<FileType> fileTypes = GetFileTypes(filesrecursive);
58     RemoveFiles(filesfileTypesverboserecursive);
59 }