•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,546 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,377 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 3163 | Replies: 8
![]() |
| |
•
•
Join Date: May 2005
Location: Kolkata
Posts: 43
Reputation:
Rep Power: 4
Solved Threads: 3
•
•
•
•
By telling us which OS/Compiler you're working with for starters.
And you also need to make sure you have a file system which records such information.
Actually I am working in a project which will be OS independent.
So pls give me some solution which will work on windows as well as Solaris.
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,541
Reputation:
Rep Power: 40
Solved Threads: 972
use the stat() or fstat() standard C library functions.
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,541
Reputation:
Rep Power: 40
Solved Threads: 972
•
•
•
•
Thanx for your answer.
Now suppose I've a pointer of ifstream. Is there are any way to get the timestamp of that file from that pointer?
The stat() function does not require an open file and is compatible for every standard compliant C and C++ compiler.
Last edited by Ancient Dragon : Oct 15th, 2007 at 9:06 am.
•
•
Join Date: Dec 2006
Location: india
Posts: 1,085
Reputation:
Rep Power: 9
Solved Threads: 163
boost::filesystem library provides portable facilities to query and manipulate paths, files, and directories.
it supports operating systems which provide either the POSIX or Windows API and is in regular use on a number of platforms (including Microsoft Windows and Sun Solaris) using a variety of compilers. programs using the library are portable, both in the syntax and the semantics of program code.
tr2 has a proposal to add a filesystem library component to the C++ Standard Library. this proposal is based on boost::filesystem. http://www.boost.org/libs/filesystem...l#Introduction
unlike most of boost, this is not a header only library. (much of the library code is platform specific. the right code is chosen based on the platform settings when building.)
here is how you could use the library to get the last modified time for a file.
it supports operating systems which provide either the POSIX or Windows API and is in regular use on a number of platforms (including Microsoft Windows and Sun Solaris) using a variety of compilers. programs using the library are portable, both in the syntax and the semantics of program code.
tr2 has a proposal to add a filesystem library component to the C++ Standard Library. this proposal is based on boost::filesystem. http://www.boost.org/libs/filesystem...l#Introduction
unlike most of boost, this is not a header only library. (much of the library code is platform specific. the right code is chosen based on the platform settings when building.)
here is how you could use the library to get the last modified time for a file.
c++ Syntax (Toggle Plain Text)
#include <boost/filesystem/operations.hpp> #include <ctime> #include <iostream> #include <fstream> int main() { boost::filesystem::path path( "/usr/local/include/boost/filesystem/operations.hpp" ) ; std::time_t t = boost::filesystem::last_write_time( path ) ; std::cout << "UTC: " << std::asctime( std::gmtime(&t) ) ; // note: some file system report last write time as local time, // while others (eg. NTFS) report it as UTC. this can be checked // by creating a new file and getting it's timestamp. eg. path = "/tmp/test_file" ; { std::ofstream file( path.file_string().c_str() ); file << "test\n" ; } t = boost::filesystem::last_write_time( path ) ; std::cout << "just created UTC: " << std::asctime( std::gmtime(&t) ) ; } /** >c++ -L/usr/local/lib -lboost_filesystem filesystem.cc && ./a.out UTC: Tue Aug 14 13:17:48 2007 just created UTC: Mon Oct 15 15:13:39 2007 */
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- uploaded file moving to new directory (PHP)
- reading of file date (Java)
- Timestamp (Shell Scripting)
- FTP get (with wildcards) in Delphi? (Pascal and Delphi)
- capturing line from script output and appending to a file (Shell Scripting)
- Tar-ing and zip-ing files after a specific time frame - HELP NEEDED (Shell Scripting)
- File Attributes (Visual Basic 4 / 5 / 6)
- Redhat Linux 6.2 - ipop3d problem? (*nix Software)
- connect to text file database (Visual Basic 4 / 5 / 6)
- 81TB File Server (Networking Hardware Configuration)
Other Threads in the C++ Forum
- Previous Thread: plz... read....
- Next Thread: Issues storing singlylinked lists in a singlylinked list.



Hybrid Mode