Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ruimac

macrumors newbie
Original poster
Sep 24, 2014
14
0
I have a file in a folder. I have the path to it in a string.
How can I get the modification date of that file?

Is there any platform independent solution?
Because I need to make it work on MacOS and Windows (32bit and 64bit).
 

ruimac

macrumors newbie
Original poster
Sep 24, 2014
14
0
Oh, sorry, I forgot to tell.
I'm using C++.
I'm coding Cinema 4D plugins. And I need to compile them in Xcode, for Mac and in Visual Studio, for Windows.
So, any cross platform solution is preferable.
Will this work in C++?

Oh, by the way, my path is in this format:

/Applications/Maxon/Cinema4D 14 - DEV/plugins/PolyPaintTag/res/reg.txt
 

chown33

Moderator
Staff member
Aug 9, 2009
9,891
6,872
Beyond the pale
C functions can be called from C++.

I googled the search terms windows file modification date and it readily found the WinAPI function GetFileTime:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724320(v=vs.85).aspx

I suggest writing a function that contains a #if/#elif/#endif construct (standard C & C++; you can look it up in any decent reference). Then put each OS's platform-specific code in the appropriate section. That way you've encapsulated the platform-dependent part into a single function, and all the rest of your code calls a single function with a single API.

This wrapper function should also account for any differences in how the date/time values are represented. That is, the Posix time representation will differ from the Windows date/time representation. Here's the Posix info. You'll have to look up the Windows info.
http://en.wikipedia.org/wiki/Unix_time

To summarize, write your own function and use the usual well-known techniques for encapsulating the platform dependencies.
 

ruimac

macrumors newbie
Original poster
Sep 24, 2014
14
0
It will be harder than what I expected, then :-(
But I will not give up.
On my Mac, I have this now:
Code:
struct tm* clock;
struct stat attrib;
string sfilename;
String reg_filename;
	
Filename reg_filename = GeGetPluginPath() + Filename("res") + Filename("reg.txt"); // returns a String...
	
sfilename=tostr(reg_filename.GetString()); // convert it to string
	
// I get an error in the next line.
// the error is: No matching function for call to 'stat'
stat(sfilename, &attrib);	
clock = gmtime(&(attrib.st_mtime));

What could be wrong?
 

chown33

Moderator
Staff member
Aug 9, 2009
9,891
6,872
Beyond the pale
First, stat() is a C function. Therefore it's in the "C" namespace, as I recall. You didn't show any includes or declarations for it, so I have no way of knowing how you declared the function. If you didn't declare it, the compiler won't know what you're referring to.

Second, you should include the relevant header file: see the man page I previously linked to. The #include must also ensure that the functions declared therein are in the "C" namespace, otherwise you'll still get an error.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.