Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Setting a file's creation date from C++

0 views
Skip to first unread message

h

unread,
Mar 12, 1999, 3:00:00 AM3/12/99
to
As the subject indicates, I'm interested in setting the file creation
date of a file that already exists. I'm familiar with the _stat
function for inquiring the creation date (among other things), but can't
find a corresponding function that sets these attributes. Surely there
must be something out there since there are shareware utilities that do
this. Can anyone point me in the right direction?

Thanks in advance.

Ken Herndon
Arpali Software


Russ Freeman

unread,
Mar 12, 1999, 3:00:00 AM3/12/99
to
Here is a function that I use, if should demonstrate how to do it - ignore
the CDateTime references.
bool FASTCALL SetFileDateTime( LPCTSTR pcszFilename, const CDateTime
&dtFile )
{
SYSTEMTIME st;
st.wYear = static_cast<unsigned short>( dtFile.GetYear() );
st.wMonth = static_cast<unsigned short>( dtFile.GetMonth() + 1 );
st.wDayOfWeek = static_cast<unsigned short>( dtFile.GetDayOfWeek() );
st.wDay = static_cast<unsigned short>( dtFile.GetDay() );
st.wHour = static_cast<unsigned short>( dtFile.GetHour() );
st.wMinute = static_cast<unsigned short>( dtFile.GetMinute() );
st.wSecond = 0;
st.wMilliseconds = 0;

FILETIME ft;
SystemTimeToFileTime( &st, &ft );

HANDLE hFile = ::CreateFile( pcszFilename, GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
bool bRetVal = false;
if( SetFileTime( hFile,(LPFILETIME) NULL, (LPFILETIME) NULL, &ft) )
{
bRetVal = true;
}
CloseHandle( hFile );
return bRetVal;
}

--
ru...@gipsysoft.com
http://www.gipsysoft.com
Zoom+, Zoom in, out, capture, count pixels, get the colour at the cursor
copy to clipboard, save to file, all of the features you expect.
QHTM, Small, light Win32 HTML control in just one 200k DLL.

h wrote in message <36E89F6F...@miele-herndon.com>...

Chris Marriott

unread,
Mar 12, 1999, 3:00:00 AM3/12/99
to

h wrote in message <36E89F6F...@miele-herndon.com>...
>As the subject indicates, I'm interested in setting the file creation
>date of a file that already exists. I'm familiar with the _stat
>function for inquiring the creation date (among other things), but can't
>find a corresponding function that sets these attributes. Surely there
>must be something out there since there are shareware utilities that do
>this. Can anyone point me in the right direction?


Use the cunningly hidden "SetFileTime" API.

Chris
-----------------------------------------------------------------------
Chris Marriott, SkyMap Software, UK (ch...@skymap.com)
Visit our web site at http://www.skymap.com
Astronomy software written by astronomers, for astronomers

Josh Pollock

unread,
Mar 12, 1999, 3:00:00 AM3/12/99
to
In article <36E89F6F...@miele-herndon.com>,

h <k...@miele-herndon.com> wrote:
>As the subject indicates, I'm interested in setting the file creation
>date of a file that already exists. I'm familiar with the _stat
>function for inquiring the creation date (among other things), but can't
>find a corresponding function that sets these attributes. Surely there
>must be something out there since there are shareware utilities that do
>this. Can anyone point me in the right direction?

SetFileTime


Ladislav Sedivy

unread,
Mar 14, 1999, 3:00:00 AM3/14/99
to
h wrote:
>
> As the subject indicates, I'm interested in setting the file creation
> date of a file that already exists. I'm familiar with the _stat
> function for inquiring the creation date (among other things), but can't
> find a corresponding function that sets these attributes. Surely there
> must be something out there since there are shareware utilities that do
> this. Can anyone point me in the right direction?
>
> Thanks in advance.
>
> Ken Herndon
> Arpali Software

I wrote a small program that modifies the date/time stamp for files and
directories.

Features not found in other "time stampers":

- will recurse sub directories
- will modify directory date/time as well
- will modify date/time of a read only file or directory
(without changing the attributes)
- will modify all three attributes (created, modified,
last accessed)
- allows for "try run" - that is you can run it just to see
what files will be affected - no modification is done.

EXE and source are in:

ftp://rabbit.apexsc.com/pub/tstamp.zip (36k)

To see the options and syntax type TSTAMP.EXE with no arguments. This
is a Win32 console program therefore it will not work in "real" DOS
window :)

enjoy
--
Lac

0 new messages