🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
13 messages
13 total messages Started by Helmut Giese Wed, 05 Mar 2003 22:53
Change timestamp of a directory
#17697
Author: Helmut Giese
Date: Wed, 05 Mar 2003 22:53
5 lines
951 bytes
Hello out there,
is it possible to change the timestamp of a directory once it has been
created? All my attempts so far have been remarkably unsuccessful.
Best regards
Helmut Giese
Re: Change timestamp of a directory
#17706
Author: Nico Bendlin
Date: Wed, 05 Mar 2003 23:05
13 lines
1502 bytes
Helmut Giese wrote:
> Hello out there,
> is it possible to change the timestamp of a directory once it has been
> created? All my attempts so far have been remarkably unsuccessful.

On WinNT use CreateFile with FILE_FLAG_BACKUP_SEMANTICS flag
(requires the privileges SE_BACKUP_NAME and SE_RESTORE_NAME).

Secondly, an diretory has only one timestamp (CreationTime).
Do not try to set LastAccessTime or LastWriteTime at all.

-- 
codito, ergo sum :]
Re: Change timestamp of a directory
#17702
Author: Remy Lebeau (TeamB)
Date: Wed, 05 Mar 2003 23:17
26 lines
1783 bytes
"Helmut Giese" <hgiese@ratiosoft.com> wrote in message
news:3e667f83.3979706@forums.borland.com...

> is it possible to change the timestamp of a directory
> once it has been created?

Which OS are you using exactly?

Under WinNT/2K/XP, you can use CreateFile() to get a HANDLE to a folder and
then use Get/SetFileTime() with it.

Under Win9x/Me, you'll have to instead do some low-level assembly
programming to communicate with the FileSystem directly to accomplish that,
using Int 21h function 7143h:

Interrupt 21h Function 7143h
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/win9x/95fun
c_29ew.asp

It might be possible to use CreateFile() with VWIN32.VXD to control the Int
21h calling for you, but I haven't tried it myself.  VWIN32.VXD supports
Int21h, but I don't know if it supports Function 7143h.


Gambit
Re: Change timestamp of a directory
#17692
Author: Helmut Giese
Date: Wed, 05 Mar 2003 23:23
21 lines
1540 bytes
On Wed, 05 Mar 2003 22:53:36 GMT, hgiese@ratiosoft.com (Helmut Giese)
wrote:

>Hello out there,
>is it possible to change the timestamp of a directory once it has been
>created? All my attempts so far have been remarkably unsuccessful.
>Best regards
>Helmut Giese
Hey, that's an incredible turn-around time. Marvellous.

Nico, thanks for the info. I'm on Win98, but the code should perform
the same on any platform.

Gambit, you don't cease to surprise me. You really do know an awful
lot of things.
Going to the technical side: No, I don't want to do assembler - I used
to be an assembler (system) programmer, but I just don't want it
anymore. The feature just got dropped :)

Many thanks to both of you.
Helmut Giese
Re: Change timestamp of a directory
#17709
Author: Remy Lebeau (TeamB)
Date: Thu, 06 Mar 2003 00:16
23 lines
1885 bytes
"Helmut Giese" <hgiese@ratiosoft.com> wrote in message
news:3e668598.5536754@forums.borland.com...

> I'm on Win98, but the code should perform the same on
> any platform.

In order to do that, you're going to have to also detect the OS version at
runtime and then execute the appropriate code based on which OS you're
running under.  You use the GetVersionEx() function to know which OS you're
currently under, testing the version numbers for known values as documented
by Microsoft.  The VCL already calls GetVersionEx() for you at startup and
stores the results in various global variables.  In this particular case,
you don't really need to know the exact versions, just which kernel platform
is being used.  You can use the Win32Platform variable for that, ie:

    if( Win32Platform == VER_PLATFORM_WIN32_NT )
        // perform WinNT/2K/NT code
    else
        // perform Win9x/Me code


Gambit
Re: Change timestamp of a directory
#17624
Author: Remy Lebeau (TeamB)
Date: Thu, 06 Mar 2003 00:18
13 lines
1475 bytes
If you look at the MSDN article I posted you to, it gives you the exact
assembly code.  Fortunately, it's only a few lines, and also that Builder
supports you to embed assembly code directly into your C++ code.


Gambit

"Helmut Giese" <hgiese@ratiosoft.com> wrote in message
news:3e668598.5536754@forums.borland.com...

> Going to the technical side: No, I don't want to do assembler -
> I used to be an assembler (system) programmer, but I just
> don't want it anymore. The feature just got dropped :)
Re: Change timestamp of a directory
#17626
Author: Ed Mulroy [TeamB]
Date: Thu, 06 Mar 2003 02:13
30 lines
1758 bytes
This is more steps but easy and works on all versions of Windows.


Make a new, temp directory with some name

Move all the files to the temp directory

Remove the original directory

Read and save the system time and date and immediately set system time and
date to the timestamp you want

Make a new directory with the name you want

Move the files to the new directory

Remove the temp directory

Using the amount of time that has elapsed since you set the phony time and
date, add that to the saved values and set the system time and date.


.  Ed

> Helmut Giese wrote in message
> news:3e667f83.3979706@forums.borland.com...
>
> is it possible to change the timestamp of a directory
> once it has been created? All my attempts so far have
> been remarkably unsuccessful.
Re: Change timestamp of a directory
#17691
Author: Helmut Giese
Date: Thu, 06 Mar 2003 13:51
39 lines
2084 bytes
On Wed, 5 Mar 2003 21:13:00 -0500, "Ed Mulroy [TeamB]" <ed@mulroy.org>
wrote:

>This is more steps but easy and works on all versions of Windows.
>
>
>Make a new, temp directory with some name
>
>Move all the files to the temp directory
>
>Remove the original directory
>
>Read and save the system time and date and immediately set system time and
>date to the timestamp you want
>
>Make a new directory with the name you want
>
>Move the files to the new directory
>
>Remove the temp directory
>
>Using the amount of time that has elapsed since you set the phony time and
>date, add that to the saved values and set the system time and date.
Hm, I thought of that, too. But when going this route everything has
to work out 100% - no error allowed - never. Or else the system time
will remain set at an arbitrary point in the past - and leave a very
puzzled user. 
But thanks for this idea, I'll keep it in mind.
Best regards
Helmut Giese

>> Helmut Giese wrote in message
>> news:3e667f83.3979706@forums.borland.com...
>>
>> is it possible to change the timestamp of a directory
>> once it has been created? All my attempts so far have
>> been remarkably unsuccessful.
>
>
Re: Change timestamp of a directory
#17694
Author: Helmut Giese
Date: Thu, 06 Mar 2003 13:54
21 lines
1664 bytes
On Wed, 5 Mar 2003 16:18:10 -0800, "Remy Lebeau \(TeamB\)"
<gambit47@yahoo.com> wrote:

>If you look at the MSDN article I posted you to, it gives you the exact
>assembly code.  Fortunately, it's only a few lines, and also that Builder
>supports you to embed assembly code directly into your C++ code.
>
Hi Gambit,
you *are* a convincing guy. Maybe I'll don't drop this feature
altogether but save it for version 2.
Thanks
Helmut Giese

>"Helmut Giese" <hgiese@ratiosoft.com> wrote in message
>news:3e668598.5536754@forums.borland.com...
>
>> Going to the technical side: No, I don't want to do assembler -
>> I used to be an assembler (system) programmer, but I just
>> don't want it anymore. The feature just got dropped :)
>
>
Re: Change timestamp of a directory
#17704
Author: Ed Mulroy [TeamB]
Date: Thu, 06 Mar 2003 14:45
20 lines
1986 bytes
> Helmut Giese wrote in message
> news:3e675170.1917379@forums.borland.com...
> Hm, I thought of that, too. But when going this
> route everything has to work out 100% - no error
> allowed - never. Or else the system time
> will remain set at an arbitrary point in the past
> - and leave a very puzzled user.

When Windows 3.0 (yes, the replacement for Win 386) came out I was greatly
bothered by how it commonly would lock up a program of any size.  I used to
do this by executing a second, small exe with a hidden window which would
accept a set of messages.  I would tell it what my main window's caption was
(so it could find the window later), and what the original and phony time
was.  This 2nd app would look for the first window and if found would then
yield.  If it did not find the first window it would check the time and date
and if wildly off, adjust the time.  It would then quit.

Things are better these days but I still do that.

.  Ed
Re: Change timestamp of a directory
#17716
Author: Helmut Giese
Date: Thu, 06 Mar 2003 19:45
29 lines
2422 bytes
On Thu, 6 Mar 2003 09:45:37 -0500, "Ed Mulroy [TeamB]" <ed@mulroy.org>
wrote:

>> Helmut Giese wrote in message
>> news:3e675170.1917379@forums.borland.com...
>> Hm, I thought of that, too. But when going this
>> route everything has to work out 100% - no error
>> allowed - never. Or else the system time
>> will remain set at an arbitrary point in the past
>> - and leave a very puzzled user.
>
>When Windows 3.0 (yes, the replacement for Win 386) came out I was greatly
>bothered by how it commonly would lock up a program of any size.  I used to
>do this by executing a second, small exe with a hidden window which would
>accept a set of messages.  I would tell it what my main window's caption was
>(so it could find the window later), and what the original and phony time
>was.  This 2nd app would look for the first window and if found would then
>yield.  If it did not find the first window it would check the time and date
>and if wildly off, adjust the time.  It would then quit.
What a sneaky way :)
Ok, I concede that this looks like a rather reliable approach.
However, the problem I'm trying to solve looks like a minor issue
right now - hey, even when I unzip archives with commercial tools I
don't get the original timestamp for directories. For my app, I'll
wait until this feature gets requested - then do some big eye-rolling,
"oh, oh, complicated stuff you're asking there" -- while all the time
having a solution ready.
Thanks a lot for your advice.
Helmut Giese
Re: Change timestamp of a directory
#17698
Author: Ed Mulroy [TeamB]
Date: Fri, 07 Mar 2003 01:13
8 lines
1350 bytes
FWIW:

What you also can do is to make the small second program a data block in
your program.  If you need it, create the file and execute it.  That way you
do not have to distribute two files.  (Also, when the program starts, if the
file exists, delete it.)

.  Ed
Re: Change timestamp of a directory
#17632
Author: Helmut Giese
Date: Fri, 07 Mar 2003 13:47
13 lines
1523 bytes
On Thu, 6 Mar 2003 20:13:56 -0500, "Ed Mulroy [TeamB]" <ed@mulroy.org>
wrote:

>FWIW:
>
>What you also can do is to make the small second program a data block in
>your program.  If you need it, create the file and execute it.  That way you
>do not have to distribute two files.  (Also, when the program starts, if the
>file exists, delete it.)
Thanks,
I'll add it to my bags of tricks.
Best regards
Helmut Giese
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads