[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

Set File Date Time Fails

BeeJ

7/22/2011 4:14:00 PM

I am copying several thousand files and keeping the date/time of the
source at the destination.
On maybe one out of 1000 files the set file date time fails.
Using the APIs to get and set date/time.
This all works on the other 999 of 1000 files copied.
So I built in a test and loop up to ten times with a 10 mSec wait on
each attempts. This still fails for some but for others it works. The
file in question attributes are normal only.
However, when I break the code in the IDE and manually step through the
date/time successfully changes every time. In my test case, the files
are going to a network share.

What is going on here?
What can I do to fix this?


8 Answers

John Simpson

7/22/2011 6:50:00 PM

0



"BeeJ" wrote in message news:j0c7k0$5ro$1@speranza.aioe.org...

I am copying several thousand files and keeping the date/time of the
source at the destination.
On maybe one out of 1000 files the set file date time fails.
Using the APIs to get and set date/time.
This all works on the other 999 of 1000 files copied.
So I built in a test and loop up to ten times with a 10 mSec wait on
each attempts. This still fails for some but for others it works. The
file in question attributes are normal only.
However, when I break the code in the IDE and manually step through the
date/time successfully changes every time. In my test case, the files
are going to a network share.

What is going on here?
What can I do to fix this?

Doevents?

ralph

7/22/2011 8:20:00 PM

0

On Fri, 22 Jul 2011 09:13:49 -0700, BeeJ <nospam@live.com> wrote:

>I am copying several thousand files and keeping the date/time of the
>source at the destination.
>On maybe one out of 1000 files the set file date time fails.
>Using the APIs to get and set date/time.
>This all works on the other 999 of 1000 files copied.
>So I built in a test and loop up to ten times with a 10 mSec wait on
>each attempts. This still fails for some but for others it works. The
>file in question attributes are normal only.
>However, when I break the code in the IDE and manually step through the
>date/time successfully changes every time. In my test case, the files
>are going to a network share.
>
>What is going on here?
>What can I do to fix this?
>

A bulk multiple file copy while also touching them in the process is
often problematic across a wire. Resources (file locks, handles, etc.)
have become all most 'unlimited' with modern computing - but we ain't
there yet. <g>

Timing and rearrangment is always the solution, but difficult to
recommend anything, without seeing how you are going about it. Post
either the actual code (best) or in rough psuedocode, what it is you
are trying to do.

-ralph

Jason Keats

7/23/2011 12:48:00 AM

0

John Simpson wrote:
> "BeeJ" wrote in message news:j0c7k0$5ro$1@speranza.aioe.org...
> I am copying several thousand files and keeping the date/time of the
> source at the destination.
> On maybe one out of 1000 files the set file date time fails.

I'd send them as a zip file. When you unzip them at the other end I
believe they retain their original attributes and modified/created time.

BeeJ

7/23/2011 2:57:00 PM

0

BeeJ explained :
> I am copying several thousand files and keeping the date/time of the source
> at the destination.
> On maybe one out of 1000 files the set file date time fails.
> Using the APIs to get and set date/time.
> This all works on the other 999 of 1000 files copied.
> So I built in a test and loop up to ten times with a 10 mSec wait on each
> attempts. This still fails for some but for others it works. The file in
> question attributes are normal only.
> However, when I break the code in the IDE and manually step through the
> date/time successfully changes every time. In my test case, the files are
> going to a network share.
>
> What is going on here?
> What can I do to fix this?

I have modified my sub and do the following

check to see the drive type
if network drive then set for a wait long time rather than a short
wait time
if the redate succeeds the proceed without delay
if not wait the prescribed time and loop to retry.
loop a max number of times then fail if it still does not succeed.

So far this seems to work.


(nobody)

7/23/2011 4:22:00 PM

0

"BeeJ" <nospam@live.com> wrote in message
news:j0c7k0$5ro$1@speranza.aioe.org...
>I am copying several thousand files and keeping the date/time of the source
>at the destination.
> On maybe one out of 1000 files the set file date time fails.
> Using the APIs to get and set date/time.
> This all works on the other 999 of 1000 files copied.
> So I built in a test and loop up to ten times with a 10 mSec wait on each
> attempts. This still fails for some but for others it works. The file in
> question attributes are normal only.
> However, when I break the code in the IDE and manually step through the
> date/time successfully changes every time. In my test case, the files are
> going to a network share.
>
> What is going on here?
> What can I do to fix this?

Besides what others suggested, it seems that there is an Anti-Virus program
locking the file just after you close it, and before you adjust the time.
Try using FileCopy Statement, or the API function CopyFile(). If you want
progress, try CopyFileEx() API function.



Anton

7/23/2011 11:16:00 PM

0

on 2011/07/23, Nobody supposed :
> "BeeJ" <nospam@live.com> wrote in message
> news:j0c7k0$5ro$1@speranza.aioe.org...
>>I am copying several thousand files and keeping the date/time of the source
>> at the destination.
>> On maybe one out of 1000 files the set file date time fails.
>> Using the APIs to get and set date/time.
>> This all works on the other 999 of 1000 files copied.
>> So I built in a test and loop up to ten times with a 10 mSec wait on each
>> attempts. This still fails for some but for others it works. The file in
>> question attributes are normal only.
>> However, when I break the code in the IDE and manually step through the
>> date/time successfully changes every time. In my test case, the files are
>> going to a network share.
>>
>> What is going on here?
>> What can I do to fix this?

> Besides what others suggested, it seems that there is an Anti-Virus program
> locking the file just after you close it, and before you adjust the time. Try
> using FileCopy Statement, or the API function CopyFile(). If you want
> progress, try CopyFileEx() API function.

Very possible. Already using full API copy with flush buffers etc.
The delay routine has run on 40GBytes of files of all sizes without
fail this time so I think the delay routine I added did the trick.
I have more trial runs tonight and tomorrow. We will see.


David Kaye

7/23/2011 11:56:00 PM

0

"BeeJ" <nospam@live.com> wrote

>I am copying several thousand files and keeping the date/time of the source
>at the destination.
> On maybe one out of 1000 files the set file date time fails.
> Using the APIs to get and set date/time.

Another possibility might be foreign characters in the filenames. While
Windows is set up for Unicode characters, the VBA commands such as filecopy
are not. They would work fine in the country of origin (such as Norwegian
filenames in Norway), but foreign characters don't work well in the USA.

I have some music files that have Czech and Bulgarian names on them, and the
various copying and filedatetime functions choke on them. But *some*
foreign characters are all right, such as the Mexican vowel accents and the
enye (the N with the squiggle on top), come out just fine. That's because
they're part of the "upper ascii" character set.



ralph

7/24/2011 5:09:00 PM

0

On Sat, 23 Jul 2011 16:56:18 -0700, "David Kaye"
<sfdavidkaye2@yahoo.com> wrote:

>"BeeJ" <nospam@live.com> wrote
>
>>I am copying several thousand files and keeping the date/time of the source
>>at the destination.
>> On maybe one out of 1000 files the set file date time fails.
>> Using the APIs to get and set date/time.
>
>Another possibility might be foreign characters in the filenames. While
>Windows is set up for Unicode characters, the VBA commands such as filecopy
>are not. They would work fine in the country of origin (such as Norwegian
>filenames in Norway), but foreign characters don't work well in the USA.
>
>I have some music files that have Czech and Bulgarian names on them, and the
>various copying and filedatetime functions choke on them. But *some*
>foreign characters are all right, such as the Mexican vowel accents and the
>enye (the N with the squiggle on top), come out just fine. That's because
>they're part of the "upper ascii" character set.
>

Thought of something like that or other "internal" attributes (and
still might be - we don't know if his test data is consistent), but
the OP said it worked fine when he stepped through the code using the
VBIDE debugger or with a different architecture.

It would seem the problems in the initial "loop process" stem simply
from out-running pending locks and system services. It happens.

-ralph