•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 397,982 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,740 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:
Views: 2459 | Replies: 8
![]() |
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.
And you also need to make sure you have a file system which records such information.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,644
Reputation:
Rep Power: 36
Solved Threads: 869
use the stat() or fstat() standard C library functions.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
•
•
Join Date: May 2005
Location: Kolkata
Posts: 33
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.
You're out of luck then, the answer is inherently platform dependent.
If it was platform independent, I wouldn't have needed to ask would I ?
If it was platform independent, I wouldn't have needed to ask would I ?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,644
Reputation:
Rep Power: 36
Solved Threads: 869
•
•
•
•
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 8:06 am.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
•
•
Join Date: Dec 2006
Location: india
Posts: 1,056
Reputation:
Rep Power: 9
Solved Threads: 159
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 */
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
Similar Threads
- 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)
- uploaded file moving to new directory (PHP)
- 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.



Linear Mode