OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file contains utility functions for dealing with the local | 5 // This file contains utility functions for dealing with the local |
6 // filesystem. | 6 // filesystem. |
7 | 7 |
8 #ifndef BASE_FILE_UTIL_H_ | 8 #ifndef BASE_FILE_UTIL_H_ |
9 #define BASE_FILE_UTIL_H_ | 9 #define BASE_FILE_UTIL_H_ |
10 | 10 |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 | 12 |
13 #if defined(OS_WIN) | 13 #if defined(OS_WIN) |
14 #include <windows.h> | 14 #include <windows.h> |
15 #elif defined(OS_POSIX) | 15 #elif defined(OS_POSIX) |
16 #include <fts.h> | 16 #include <fts.h> |
17 #include <sys/stat.h> | 17 #include <sys/stat.h> |
18 #endif | 18 #endif |
19 | 19 |
20 #include <stdio.h> | 20 #include <stdio.h> |
21 | 21 |
22 #include <stack> | 22 #include <stack> |
23 #include <string> | 23 #include <string> |
24 #include <vector> | 24 #include <vector> |
25 | 25 |
26 #include "base/basictypes.h" | 26 #include "base/basictypes.h" |
27 #include "base/scoped_ptr.h" | 27 #include "base/scoped_ptr.h" |
28 #include "base/file_path.h" | 28 #include "base/file_path.h" |
29 | 29 |
30 namespace base { | |
31 class Time; | |
32 } | |
33 | |
34 namespace file_util { | 30 namespace file_util { |
35 | 31 |
36 //----------------------------------------------------------------------------- | 32 //----------------------------------------------------------------------------- |
37 // Functions that operate purely on a path string w/o touching the filesystem: | 33 // Functions that operate purely on a path string w/o touching the filesystem: |
38 | 34 |
39 // Returns a vector of all of the components of the provided path. | 35 // Returns a vector of all of the components of the provided path. |
40 void PathComponents(const FilePath& path, | 36 void PathComponents(const FilePath& path, |
41 std::vector<FilePath::StringType>* components); | 37 std::vector<FilePath::StringType>* components); |
42 #if defined(OS_WIN) | 38 #if defined(OS_WIN) |
43 // Deprecated temporary compatibility function. | 39 // Deprecated temporary compatibility function. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 // Example: | 128 // Example: |
133 // file_name == "bad:file*name?.txt", changed to: "bad-file-name-.txt" when | 129 // file_name == "bad:file*name?.txt", changed to: "bad-file-name-.txt" when |
134 // 'replace_char' is '-'. | 130 // 'replace_char' is '-'. |
135 void ReplaceIllegalCharacters(std::wstring* file_name, int replace_char); | 131 void ReplaceIllegalCharacters(std::wstring* file_name, int replace_char); |
136 | 132 |
137 //----------------------------------------------------------------------------- | 133 //----------------------------------------------------------------------------- |
138 // Functions that involve filesystem access or modification: | 134 // Functions that involve filesystem access or modification: |
139 | 135 |
140 #if defined(OS_WIN) | 136 #if defined(OS_WIN) |
141 // Returns the number of files matching the current path that were | 137 // Returns the number of files matching the current path that were |
142 // created on or after the given |file_time|. Doesn't count ".." or ".". | 138 // created on or after the given FILETIME. Doesn't count ".." or ".". |
143 int CountFilesCreatedAfter(const FilePath& path, | 139 // Filetime is UTC filetime, not LocalFiletime. |
144 const base::Time& file_time); | 140 int CountFilesCreatedAfter(const std::wstring& path, |
| 141 const FILETIME& file_time); |
145 #endif // defined(OS_WIN) | 142 #endif // defined(OS_WIN) |
146 | 143 |
147 // Deletes the given path, whether it's a file or a directory. | 144 // Deletes the given path, whether it's a file or a directory. |
148 // If it's a directory, it's perfectly happy to delete all of the | 145 // If it's a directory, it's perfectly happy to delete all of the |
149 // directory's contents. Passing true to recursive deletes | 146 // directory's contents. Passing true to recursive deletes |
150 // subdirectories and their contents as well. | 147 // subdirectories and their contents as well. |
151 // Returns true if successful, false otherwise. | 148 // Returns true if successful, false otherwise. |
152 // | 149 // |
153 // WARNING: USING THIS WITH recursive==true IS EQUIVALENT | 150 // WARNING: USING THIS WITH recursive==true IS EQUIVALENT |
154 // TO "rm -rf", SO USE WITH CAUTION. | 151 // TO "rm -rf", SO USE WITH CAUTION. |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 | 505 |
509 // Renames a file using the SHFileOperation API to ensure that the target file | 506 // Renames a file using the SHFileOperation API to ensure that the target file |
510 // gets the correct default security descriptor in the new path. | 507 // gets the correct default security descriptor in the new path. |
511 bool RenameFileAndResetSecurityDescriptor( | 508 bool RenameFileAndResetSecurityDescriptor( |
512 const FilePath& source_file_path, | 509 const FilePath& source_file_path, |
513 const FilePath& target_file_path); | 510 const FilePath& target_file_path); |
514 | 511 |
515 } // namespace file_util | 512 } // namespace file_util |
516 | 513 |
517 #endif // BASE_FILE_UTIL_H_ | 514 #endif // BASE_FILE_UTIL_H_ |
OLD | NEW |