Getting directory creation date and time??? 
Author Message
 Getting directory creation date and time???

Hello all,

I was looking for a way of retrieving a directory creation date and time ...
but it seems there is no straight way to accomplish this. I have found only
two possible solutions: (1) using the FindFirstFile call and (2) using the
CreateFile (with the FILE_FLAG_BACKUP_SEMANTICS flag set that however works
only on NT/2K/XP platforms) and the GetFileTime functions. So if I want to
write code that works on all MS platforms I'll have to use the FindFirstFile
function. Is this correct or am I missing another maybe better solution???

Regards,
Bob Rock



Sat, 03 Sep 2005 23:16:30 GMT  
 Getting directory creation date and time???
Bob,

Both of the options GetFileTime and FindFirstFile are ok and will work on
Win95 and later.

--
Regards,
  Kobi Ben Tzvi


Quote:
> Hello all,

> I was looking for a way of retrieving a directory creation date and time
...
> but it seems there is no straight way to accomplish this. I have found
only
> two possible solutions: (1) using the FindFirstFile call and (2) using the
> CreateFile (with the FILE_FLAG_BACKUP_SEMANTICS flag set that however
works
> only on NT/2K/XP platforms) and the GetFileTime functions. So if I want to
> write code that works on all MS platforms I'll have to use the
FindFirstFile
> function. Is this correct or am I missing another maybe better solution???

> Regards,
> Bob Rock



Sat, 03 Sep 2005 23:27:47 GMT  
 Getting directory creation date and time???


Quote:
> Bob,

> Both of the options GetFileTime and FindFirstFile are ok and will work on
> Win95 and later.

> --
> Regards,
>   Kobi Ben Tzvi

Kobi, but how can you get a file handle under win9x/winME? I believe the
CreateFile flag FILE_FLAG_BACKUP_SEMANTICS is available only under NT/2K/XP.

Bob Rock



Sat, 03 Sep 2005 23:36:19 GMT  
 Getting directory creation date and time???
Bob,

To get handle you need to call CreateFile but  FILE_FLAG_BACKUP_SEMANTICS is
unnecessary. You can use GENERIC_READ and FILE_SHARE_READ.

Sample(no error handlings...):

FILETIME ftCreationTime = 0;
FILETIME ftLastAccessTime = 0;
FILETIME ftLastWriteTime = 0;
HANDLE hFile =
CreateFile("c:\\1.jpg",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NUL
L);
GetFileTime(hFile,&ftCreationTime,&ftLastAccessTime,&ftLastWriteTime);
CloseHandle(hFile);

--
Regards,
  Kobi Ben Tzvi


Quote:


> > Bob,

> > Both of the options GetFileTime and FindFirstFile are ok and will work
on
> > Win95 and later.

> > --
> > Regards,
> >   Kobi Ben Tzvi

> Kobi, but how can you get a file handle under win9x/winME? I believe the
> CreateFile flag FILE_FLAG_BACKUP_SEMANTICS is available only under
NT/2K/XP.

> Bob Rock



Sat, 03 Sep 2005 23:52:38 GMT  
 Getting directory creation date and time???
Oops,

Quote:
> FILETIME ftCreationTime = 0;
> FILETIME ftLastAccessTime = 0;
> FILETIME ftLastWriteTime = 0;

is wrong.

need to remove "= 0";

Fixed:

FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;

--
Regards,
  Kobi Ben Tzvi



Quote:
> Bob,

> To get handle you need to call CreateFile but  FILE_FLAG_BACKUP_SEMANTICS
is
> unnecessary. You can use GENERIC_READ and FILE_SHARE_READ.

> Sample(no error handlings...):

> FILETIME ftCreationTime = 0;
> FILETIME ftLastAccessTime = 0;
> FILETIME ftLastWriteTime = 0;
> HANDLE hFile =

CreateFile("c:\\1.jpg",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NUL
Quote:
> L);
> GetFileTime(hFile,&ftCreationTime,&ftLastAccessTime,&ftLastWriteTime);
> CloseHandle(hFile);

> --
> Regards,
>   Kobi Ben Tzvi





> > > Bob,

> > > Both of the options GetFileTime and FindFirstFile are ok and will work
> on
> > > Win95 and later.

> > > --
> > > Regards,
> > >   Kobi Ben Tzvi

> > Kobi, but how can you get a file handle under win9x/winME? I believe the
> > CreateFile flag FILE_FLAG_BACKUP_SEMANTICS is available only under
> NT/2K/XP.

> > Bob Rock



Sat, 03 Sep 2005 23:57:19 GMT  
 Getting directory creation date and time???
Kobi sorry to say it but although it works for a file it does not work for a
directory.

 HANDLE hDir = CreateFile("d:\\winnt\\",
         GENERIC_READ,
         FILE_SHARE_READ,
         NULL,
         OPEN_EXISTING,
         0,
         NULL);

You can try the previous call and see for yourself. The only way to make
this call work is to use the FILE_FLAG_BACKUP_SEMANTICS flag.

Bob Rock



Sun, 04 Sep 2005 00:08:42 GMT  
 Getting directory creation date and time???
Bob,

I thought you wanted file dates, my fault.
Use FindFirstFile to get directory dates.

--
Regards,
  Kobi Ben Tzvi


Quote:
> Kobi sorry to say it but although it works for a file it does not work for
a
> directory.

>  HANDLE hDir = CreateFile("d:\\winnt\\",
>          GENERIC_READ,
>          FILE_SHARE_READ,
>          NULL,
>          OPEN_EXISTING,
>          0,
>          NULL);

> You can try the previous call and see for yourself. The only way to make
> this call work is to use the FILE_FLAG_BACKUP_SEMANTICS flag.

> Bob Rock



Sun, 04 Sep 2005 00:19:37 GMT  
 Getting directory creation date and time???
See KB article

            Q105306 - HOWTO: Get and Use a Handle to a Directory

--
Cheers
Check Abdoul [ VC++ MVP ]
-----------------------------------


Quote:
> Kobi sorry to say it but although it works for a file it does not work for
a
> directory.

>  HANDLE hDir = CreateFile("d:\\winnt\\",
>          GENERIC_READ,
>          FILE_SHARE_READ,
>          NULL,
>          OPEN_EXISTING,
>          0,
>          NULL);

> You can try the previous call and see for yourself. The only way to make
> this call work is to use the FILE_FLAG_BACKUP_SEMANTICS flag.

> Bob Rock



Sun, 04 Sep 2005 00:32:28 GMT  
 Getting directory creation date and time???

Quote:
>only on NT/2K/XP platforms) and the GetFileTime functions. So if I want to
>write code that works on all MS platforms I'll have to use the FindFirstFile
>function. Is this correct or am I missing another maybe better solution???

A directory is a type of file. You can get the date and time of a
directory the same way you would for a file.

I haven't done it, but I'd imagine that if c:\mydir didn't work then
c:\mydir\. would work (note the trailing \ and trailing .)

Stephen
--
Stephen Kellett
Object Media Limited    http://www.objmedia.demon.co.uk
RSI Information:        http://www.objmedia.demon.co.uk/rsi.html



Sun, 04 Sep 2005 00:28:29 GMT  
 Getting directory creation date and time???

Quote:
> See KB article

>             Q105306 - HOWTO: Get and Use a Handle to a Directory

> --
> Cheers
> Check Abdoul [ VC++ MVP ]
> -----------------------------------

I just can't believe it. I cannot find this KB article anywhere on the
internet ... not even on MS site.

Bob Rock



Sun, 04 Sep 2005 00:43:14 GMT  
 Getting directory creation date and time???
Stephen to call GetFileTime on a directory I need a handle to a directory.
Now, CreateFile succeeds if called on a directory only using the
FILE_FLAG_BACKUP_SEMANTICS flag which is however available only on NT/2K/XP
platforms.

Bob Rock



Sun, 04 Sep 2005 00:43:51 GMT  
 Getting directory creation date and time???
    It is available in my october 2001 msdn library. Anyway here is the gist
of the article

        http://tinyurl.com/7pfg
                +
        "This code does not work on Win32s, because MS-DOS does not support
opening a directory. If you are looking for the creation time of a
directory, use FindFirstFile(), because it works on all platforms. "

--
Cheers
Check Abdoul [ VC++ MVP ]
-----------------------------------


Quote:


> > See KB article

> >             Q105306 - HOWTO: Get and Use a Handle to a Directory

> > --
> > Cheers
> > Check Abdoul [ VC++ MVP ]
> > -----------------------------------

> I just can't believe it. I cannot find this KB article anywhere on the
> internet ... not even on MS site.

> Bob Rock



Sun, 04 Sep 2005 01:03:15 GMT  
 Getting directory creation date and time???


Quote:
>Stephen to call GetFileTime on a directory I need a handle to a directory.
>Now, CreateFile succeeds if called on a directory only using the
>FILE_FLAG_BACKUP_SEMANTICS flag which is however available only on NT/2K/XP
>platforms.

Sorry, I never include Win9x in my thinking. I don't code for it, its
not industrial strength.

What about stat() - can that work for you?
--
Stephen Kellett
Object Media Limited    http://www.objmedia.demon.co.uk
RSI Information:        http://www.objmedia.demon.co.uk/rsi.html



Sun, 04 Sep 2005 02:34:31 GMT  
 Getting directory creation date and time???
Stephen,

Quote:
> Sorry, I never include Win9x in my thinking. I don't code for it, its
> not industrial strength.

Yes but its still most used OS in world.
http://www.google.com/press/zeitgeist.html

--
Regards,
  Kobi Ben Tzvi


Quote:


> >Stephen to call GetFileTime on a directory I need a handle to a
directory.
> >Now, CreateFile succeeds if called on a directory only using the
> >FILE_FLAG_BACKUP_SEMANTICS flag which is however available only on
NT/2K/XP
> >platforms.

> Sorry, I never include Win9x in my thinking. I don't code for it, its
> not industrial strength.

> What about stat() - can that work for you?
> --
> Stephen Kellett
> Object Media Limited    http://www.objmedia.demon.co.uk
> RSI Information:        http://www.objmedia.demon.co.uk/rsi.html



Sun, 04 Sep 2005 02:41:32 GMT  
 Getting directory creation date and time???


Quote:
> Hello all,

> I was looking for a way of retrieving a directory creation date and time
...
> but it seems there is no straight way to accomplish this. I have found
only
> two possible solutions: (1) using the FindFirstFile call and (2) using the
> CreateFile (with the FILE_FLAG_BACKUP_SEMANTICS flag set that however
works
> only on NT/2K/XP platforms) and the GetFileTime functions. So if I want to
> write code that works on all MS platforms I'll have to use the
FindFirstFile
> function. Is this correct or am I missing another maybe better solution???

If you can live with Win98 or later (no Windows 95), then
GetFileAttributesEx() may work for you.

Jay



Sun, 04 Sep 2005 06:50:16 GMT  
 
 [ 15 post ] 

 Relevant Pages 

1. Getting a file list based on creation date/time

2. Directory Creation Date

3. Read directory content by creation date

4. getting the creation date of dir?

5. Getting file creation dates from ifstream.

6. getting hard disk creation date

7. File Creation Date/Time Stamp

8. File Creation Date/Time

9. QUESTION: How to set the time and date for a file's creation or modification

10. Setting creation time of a directory?

11. C time/date to Visual Basic time/date

12. Date Time Picker - Date AND Time

 

 
Powered by phpBB® Forum Software