Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(567)

Side by Side Diff: base/file_util_win.cc

Issue 73075: First step to port file_util::CountFilesCreatedAfter().... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/file_util_unittest.cc ('k') | chrome/test/automated_ui_tests/automated_ui_tests.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "base/file_util.h" 5 #include "base/file_util.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <shellapi.h> 8 #include <shellapi.h>
9 #include <shlobj.h> 9 #include <shlobj.h>
10 #include <time.h> 10 #include <time.h>
11 #include <string> 11 #include <string>
12 12
13 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/scoped_handle.h" 15 #include "base/scoped_handle.h"
16 #include "base/string_util.h" 16 #include "base/string_util.h"
17 #include "base/time.h"
17 #include "base/win_util.h" 18 #include "base/win_util.h"
18 19
19 namespace file_util { 20 namespace file_util {
20 21
21 std::wstring GetDirectoryFromPath(const std::wstring& path) { 22 std::wstring GetDirectoryFromPath(const std::wstring& path) {
22 wchar_t path_buffer[MAX_PATH]; 23 wchar_t path_buffer[MAX_PATH];
23 wchar_t* file_ptr = NULL; 24 wchar_t* file_ptr = NULL;
24 if (GetFullPathName(path.c_str(), MAX_PATH, path_buffer, &file_ptr) == 0) 25 if (GetFullPathName(path.c_str(), MAX_PATH, path_buffer, &file_ptr) == 0)
25 return L""; 26 return L"";
26 27
27 std::wstring::size_type length = 28 std::wstring::size_type length =
28 file_ptr ? file_ptr - path_buffer : path.length(); 29 file_ptr ? file_ptr - path_buffer : path.length();
29 std::wstring directory(path, 0, length); 30 std::wstring directory(path, 0, length);
30 TrimTrailingSeparator(&directory); 31 TrimTrailingSeparator(&directory);
31 return directory; 32 return directory;
32 } 33 }
33 34
34 bool AbsolutePath(FilePath* path) { 35 bool AbsolutePath(FilePath* path) {
35 wchar_t file_path_buf[MAX_PATH]; 36 wchar_t file_path_buf[MAX_PATH];
36 if (!_wfullpath(file_path_buf, path->value().c_str(), MAX_PATH)) 37 if (!_wfullpath(file_path_buf, path->value().c_str(), MAX_PATH))
37 return false; 38 return false;
38 *path = FilePath(file_path_buf); 39 *path = FilePath(file_path_buf);
39 return true; 40 return true;
40 } 41 }
41 42
42 int CountFilesCreatedAfter(const std::wstring& path, 43 int CountFilesCreatedAfter(const FilePath& path,
43 const FILETIME& comparison_time) { 44 const base::Time& comparison_time) {
44 int file_count = 0; 45 int file_count = 0;
46 FILETIME comparison_filetime(comparison_time.ToFileTime());
45 47
46 WIN32_FIND_DATA find_file_data; 48 WIN32_FIND_DATA find_file_data;
47 std::wstring filename_spec = path + L"\\*"; // All files in given dir 49 // All files in given dir
50 std::wstring filename_spec = path.Append(L"*").value();
48 HANDLE find_handle = FindFirstFile(filename_spec.c_str(), &find_file_data); 51 HANDLE find_handle = FindFirstFile(filename_spec.c_str(), &find_file_data);
49 if (find_handle != INVALID_HANDLE_VALUE) { 52 if (find_handle != INVALID_HANDLE_VALUE) {
50 do { 53 do {
51 // Don't count current or parent directories. 54 // Don't count current or parent directories.
52 if ((wcscmp(find_file_data.cFileName, L"..") == 0) || 55 if ((wcscmp(find_file_data.cFileName, L"..") == 0) ||
53 (wcscmp(find_file_data.cFileName, L".") == 0)) 56 (wcscmp(find_file_data.cFileName, L".") == 0))
54 continue; 57 continue;
55 58
56 long result = CompareFileTime(&find_file_data.ftCreationTime, 59 long result = CompareFileTime(&find_file_data.ftCreationTime,
57 &comparison_time); 60 &comparison_filetime);
58 // File was created after or on comparison time 61 // File was created after or on comparison time
59 if ((result == 1) || (result == 0)) 62 if ((result == 1) || (result == 0))
60 ++file_count; 63 ++file_count;
61 } while (FindNextFile(find_handle, &find_file_data)); 64 } while (FindNextFile(find_handle, &find_file_data));
62 FindClose(find_handle); 65 FindClose(find_handle);
63 } 66 }
64 67
65 return file_count; 68 return file_count;
66 } 69 }
67 70
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 void PathComponents(const std::wstring& path, 804 void PathComponents(const std::wstring& path,
802 std::vector<std::wstring>* components) { 805 std::vector<std::wstring>* components) {
803 PathComponents(FilePath(path), components); 806 PathComponents(FilePath(path), components);
804 } 807 }
805 void ReplaceExtension(std::wstring* file_name, const std::wstring& extension) { 808 void ReplaceExtension(std::wstring* file_name, const std::wstring& extension) {
806 FilePath path(*file_name); 809 FilePath path(*file_name);
807 ReplaceExtension(&path, extension); 810 ReplaceExtension(&path, extension);
808 file_name->assign(path.value()); 811 file_name->assign(path.value());
809 } 812 }
810 } // namespace file_util 813 } // namespace file_util
OLDNEW
« no previous file with comments | « base/file_util_unittest.cc ('k') | chrome/test/automated_ui_tests/automated_ui_tests.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698