f



How to open a file for binary access without creating an empty file if the file doesn't exist

I'd like to open a file for binary access
  Open "C:\Test\myfile.bin" For Binary Lock Read Write As #1

Unfortunately if the file does not exist an empty file is created (Visual
Basic Documentation: If the file specified by pathname doesn't exist, it is
created when a file is opened for Append, Binary, Output, or Random modes).

Today before opening the file for binary access I check if the file exists.
But I experienced situations where the file during the file check existed
and just before the opening of the file it has been removed by another
programm.

Is there really no possibility to open a file for binary access only if the
file exists and else to get an error message which I can handle with On
Error?


0
noemail10 (353)
6/13/2004 1:21:54 PM
comp.lang.basic.visual.misc 10153 articles. 0 followers. Post Follow

31 Replies
1593 Views

Similar Articles

[PageSpeed] 5

Hmm. That's an interesting question. Lookup the OpenFile API in MSDN. I
think it does exactly what you want.

Also, perhaps after (inadvertantly) creating the file using VB's Open
statement you can test for LOF(). If it's zero you probably created the
file, no? Additional I doubt that anything could happen to the file between
Psuedocode: If MyFileExists Then OpenMyFile
The operation most likely takes places in the same clock cycle.
Though, I guess, VB's Dir$ (for some reason) is pretty slow and might not.
Try FindFirstFile API instead... it's super-fast.


"Stefan Mueller" <noemail@noemail.com> wrote in message
news:cahk91$sd$1@news.eusc.inter.net...
> I'd like to open a file for binary access
>   Open "C:\Test\myfile.bin" For Binary Lock Read Write As #1
>
> Unfortunately if the file does not exist an empty file is created (Visual
> Basic Documentation: If the file specified by pathname doesn't exist, it
is
> created when a file is opened for Append, Binary, Output, or Random
modes).
>
> Today before opening the file for binary access I check if the file
exists.
> But I experienced situations where the file during the file check existed
> and just before the opening of the file it has been removed by another
> programm.
>
> Is there really no possibility to open a file for binary access only if
the
> file exists and else to get an error message which I can handle with On
> Error?
>
>


0
cmoyaX (98)
6/13/2004 2:47:14 PM
> I'd like to open a file for binary access
>   Open "C:\Test\myfile.bin" For Binary Lock Read Write As #1
> Unfortunately if the file does not exist an empty file is created
> (Visual Basic Documentation: If the file specified by pathname doesn't
> exist, it is created when a file is opened for Append, Binary, Output,
> or Random modes). 

Probably you have to settle for opening it and then if its size (LOF) is 
zero, killing it. Of course in between these two operations, someone 
might have written to it...








0
6/13/2004 2:49:28 PM
Yea, that's exactly what I tried to do. I opened the file with 'For Input'
(if the file doesn't exist anymore no empty file will be created and I get
an error which I can handle with 'On Error') and stored its size using LOF.
Then I opened the file again with 'For Binary' and compared the size. That
really works quite well, but there's still a problem.

If the original file in the meantime has been removed and I therefore
created with the open a new empty file then this file can also be opened by
another program which is also intensively opening files. Therefore I used
'Lock Read Write' so another program cannot open this file. But now, how can
I delete this empty file? I need to close and kill the file and between the
close and kill another program can !!and will!! open this empty file.

I really think I only have one solution: Somehow to open a file for binary
without creating an empty file if the file doesn't exist anymore.

Stefan


"Bert Byfield" <BertByfield@nospam.not> wrote in message
news:Xns95076E17622BDBertByfield134nospam@24.24.2.166...
> > I'd like to open a file for binary access
> >   Open "C:\Test\myfile.bin" For Binary Lock Read Write As #1
> > Unfortunately if the file does not exist an empty file is created
> > (Visual Basic Documentation: If the file specified by pathname doesn't
> > exist, it is created when a file is opened for Append, Binary, Output,
> > or Random modes).
>
> Probably you have to settle for opening it and then if its size (LOF) is
> zero, killing it. Of course in between these two operations, someone
> might have written to it...
>
>
>
>
>
>
>
>


0
noemail10 (353)
6/13/2004 3:35:37 PM
Stefan Mueller wrote:
> 
> Yea, that's exactly what I tried to do. I opened the file with 'For Input'
> (if the file doesn't exist anymore no empty file will be created and I get
> an error which I can handle with 'On Error') and stored its size using LOF.
> Then I opened the file again with 'For Binary' and compared the size. That
> really works quite well, but there's still a problem.
> 
> If the original file in the meantime has been removed and I therefore
> created with the open a new empty file then this file can also be opened by
> another program which is also intensively opening files. Therefore I used
> 'Lock Read Write' so another program cannot open this file. But now, how can
> I delete this empty file? I need to close and kill the file and between the
> close and kill another program can !!and will!! open this empty file.
> 
> I really think I only have one solution: Somehow to open a file for binary
> without creating an empty file if the file doesn't exist anymore.

Another possibility is to set the Read-only or 
Write-only attributes of the file if your (intensive)
0
ruthal (141)
6/13/2004 5:19:59 PM
Stefan Mueller wrote:
> 
> Yea, that's exactly what I tried to do. I opened the file with 'For Input'
> (if the file doesn't exist anymore no empty file will be created and I get
> an error which I can handle with 'On Error') and stored its size using LOF.
> Then I opened the file again with 'For Binary' and compared the size. That
> really works quite well, but there's still a problem.
> 
> If the original file in the meantime has been removed and I therefore
> created with the open a new empty file then this file can also be opened by
> another program which is also intensively opening files. Therefore I used
> 'Lock Read Write' so another program cannot open this file. But now, how can
> I delete this empty file? I need to close and kill the file and between the
> close and kill another program can !!and will!! open this empty file.
> 
> I really think I only have one solution: Somehow to open a file for binary
> without creating an empty file if the file doesn't exist anymore.

Sorry about the partial post - fat fingers hit the
wrong keys.

Try testing for the file without opening anything:

Function FileExists(fname As String) As Boolean
If Dir(fname) <> "" Then
    FileExists = True
Else
    FileExists = False
End If
End Function

- with thanks to whoever it was on this group 
  who posted this function originally!  :)
0
ruthal (141)
6/13/2004 5:53:46 PM
To use an API sounds good, but how can I open a file for binary access and
how can I lock the file for read/write with the OpenFile API ?

Stefan

<cmoyaX@nospam.com> wrote in message
news:40cc68f5$0$3023$61fed72c@news.rcn.com...
> Hmm. That's an interesting question. Lookup the OpenFile API in MSDN. I
> think it does exactly what you want.
>
> Also, perhaps after (inadvertantly) creating the file using VB's Open
> statement you can test for LOF(). If it's zero you probably created the
> file, no? Additional I doubt that anything could happen to the file
between
> Psuedocode: If MyFileExists Then OpenMyFile
> The operation most likely takes places in the same clock cycle.
> Though, I guess, VB's Dir$ (for some reason) is pretty slow and might not.
> Try FindFirstFile API instead... it's super-fast.
>
>
> "Stefan Mueller" <noemail@noemail.com> wrote in message
> news:cahk91$sd$1@news.eusc.inter.net...
> > I'd like to open a file for binary access
> >   Open "C:\Test\myfile.bin" For Binary Lock Read Write As #1
> >
> > Unfortunately if the file does not exist an empty file is created
(Visual
> > Basic Documentation: If the file specified by pathname doesn't exist, it
> is
> > created when a file is opened for Append, Binary, Output, or Random
> modes).
> >
> > Today before opening the file for binary access I check if the file
> exists.
> > But I experienced situations where the file during the file check
existed
> > and just before the opening of the file it has been removed by another
> > programm.
> >
> > Is there really no possibility to open a file for binary access only if
> the
> > file exists and else to get an error message which I can handle with On
> > Error?
> >
> >
>
>


0
noemail10 (353)
6/13/2004 9:48:20 PM
Thanks for the code and you hint, but between the file test and the open
there is still a very very small time where another program can remove the
file and because I'm testing a software where several programs intensively
try to access the same files over several hours, it's sometimes possible,
that a program deletes a file between the file test and the open statement.

I really think I have to find a solution to open a file for binary access
with a read/write lock which does not create an empty file if the file does
not exist anymore.

Stefan


"Randy Day" <ruthal@sasktel.nex> wrote in message
news:40CC94AA.33119366@sasktel.nex...
> Stefan Mueller wrote:
> >
> > Yea, that's exactly what I tried to do. I opened the file with 'For
Input'
> > (if the file doesn't exist anymore no empty file will be created and I
get
> > an error which I can handle with 'On Error') and stored its size using
LOF.
> > Then I opened the file again with 'For Binary' and compared the size.
That
> > really works quite well, but there's still a problem.
> >
> > If the original file in the meantime has been removed and I therefore
> > created with the open a new empty file then this file can also be opened
by
> > another program which is also intensively opening files. Therefore I
used
> > 'Lock Read Write' so another program cannot open this file. But now, how
can
> > I delete this empty file? I need to close and kill the file and between
the
> > close and kill another program can !!and will!! open this empty file.
> >
> > I really think I only have one solution: Somehow to open a file for
binary
> > without creating an empty file if the file doesn't exist anymore.
>
> Sorry about the partial post - fat fingers hit the
> wrong keys.
>
> Try testing for the file without opening anything:
>
> Function FileExists(fname As String) As Boolean
> If Dir(fname) <> "" Then
>     FileExists = True
> Else
>     FileExists = False
> End If
> End Function
>
> - with thanks to whoever it was on this group
>   who posted this function originally!  :)


0
noemail10 (353)
6/13/2004 9:59:51 PM
OpenFile is intrinsically a "binary Open." Leave out the OF_CREATE flag and
OpenFile should fail (return HFILE_ERROR) if the file doesn't exist and give
you that error that you seek. The only problem is that then you can't use
VB's own intrinsic Get/Put statements. You'll have to use the (very similar,
but not as super-easy) ReadFile/WriteFile API's... I know of no way to
convert an OpenFile handle to a VB #FileNumber.


"Stefan Mueller" <noemail@noemail.com> wrote in message
news:caihui$6u0$1@news.eusc.inter.net...
> To use an API sounds good, but how can I open a file for binary access and
> how can I lock the file for read/write with the OpenFile API ?
>
> Stefan
>
> <cmoyaX@nospam.com> wrote in message
> news:40cc68f5$0$3023$61fed72c@news.rcn.com...
> > Hmm. That's an interesting question. Lookup the OpenFile API in MSDN. I
> > think it does exactly what you want.
> >
> > Also, perhaps after (inadvertantly) creating the file using VB's Open
> > statement you can test for LOF(). If it's zero you probably created the
> > file, no? Additional I doubt that anything could happen to the file
> between
> > Psuedocode: If MyFileExists Then OpenMyFile
> > The operation most likely takes places in the same clock cycle.
> > Though, I guess, VB's Dir$ (for some reason) is pretty slow and might
not.
> > Try FindFirstFile API instead... it's super-fast.
> >
> >
> > "Stefan Mueller" <noemail@noemail.com> wrote in message
> > news:cahk91$sd$1@news.eusc.inter.net...
> > > I'd like to open a file for binary access
> > >   Open "C:\Test\myfile.bin" For Binary Lock Read Write As #1
> > >
> > > Unfortunately if the file does not exist an empty file is created
> (Visual
> > > Basic Documentation: If the file specified by pathname doesn't exist,
it
> > is
> > > created when a file is opened for Append, Binary, Output, or Random
> > modes).
> > >
> > > Today before opening the file for binary access I check if the file
> > exists.
> > > But I experienced situations where the file during the file check
> existed
> > > and just before the opening of the file it has been removed by another
> > > programm.
> > >
> > > Is there really no possibility to open a file for binary access only
if
> > the
> > > file exists and else to get an error message which I can handle with
On
> > > Error?
> > >
> > >
> >
> >
>
>


0
cmoyaX (98)
6/13/2004 10:02:48 PM
I think, though I may be wrong, that this is just the Open statement's
classic behavior. I don't think there's a "pure VB" workaround. If you don't
like the "2-step" approach (even using the super-fast FindFirstFile API) and
you need something a little more honed then:
1) Use the OpenFile API (or the MS recommened CreateFile API--- which is a
misnomer it can behave as an "open file" function). Then use the API's for
reading and writing binary data (it's not that hard).
2) Switch to VB.NET. The File I/O routines allow for the fine-tuning that
you seek.

"Stefan Mueller" <noemail@noemail.com> wrote in message
news:caiik5$71k$1@news.eusc.inter.net...
> Thanks for the code and you hint, but between the file test and the open
> there is still a very very small time where another program can remove the
> file and because I'm testing a software where several programs intensively
> try to access the same files over several hours, it's sometimes possible,
> that a program deletes a file between the file test and the open
statement.
>
> I really think I have to find a solution to open a file for binary access
> with a read/write lock which does not create an empty file if the file
does
> not exist anymore.
>
> Stefan
>
>
> "Randy Day" <ruthal@sasktel.nex> wrote in message
> news:40CC94AA.33119366@sasktel.nex...
> > Stefan Mueller wrote:
> > >
> > > Yea, that's exactly what I tried to do. I opened the file with 'For
> Input'
> > > (if the file doesn't exist anymore no empty file will be created and I
> get
> > > an error which I can handle with 'On Error') and stored its size using
> LOF.
> > > Then I opened the file again with 'For Binary' and compared the size.
> That
> > > really works quite well, but there's still a problem.
> > >
> > > If the original file in the meantime has been removed and I therefore
> > > created with the open a new empty file then this file can also be
opened
> by
> > > another program which is also intensively opening files. Therefore I
> used
> > > 'Lock Read Write' so another program cannot open this file. But now,
how
> can
> > > I delete this empty file? I need to close and kill the file and
between
> the
> > > close and kill another program can !!and will!! open this empty file.
> > >
> > > I really think I only have one solution: Somehow to open a file for
> binary
> > > without creating an empty file if the file doesn't exist anymore.
> >
> > Sorry about the partial post - fat fingers hit the
> > wrong keys.
> >
> > Try testing for the file without opening anything:
> >
> > Function FileExists(fname As String) As Boolean
> > If Dir(fname) <> "" Then
> >     FileExists = True
> > Else
> >     FileExists = False
> > End If
> > End Function
> >
> > - with thanks to whoever it was on this group
> >   who posted this function originally!  :)
>
>


0
cmoyaX (98)
6/13/2004 10:15:48 PM
Stefan Mueller wrote:
> 
> Thanks for the code and you hint, but between the file test and the open
> there is still a very very small time where another program can remove the
> file and because I'm testing a software where several programs intensively
> try to access the same files over several hours, it's sometimes possible,
> that a program deletes a file between the file test and the open statement.
> 
> I really think I have to find a solution to open a file for binary access
> with a read/write lock which does not create an empty file if the file does
> not exist anymore.

How about this:

Attempt to *rename* the file to something the 
other programs won't look for.

If no file: rename fails, and you get an error 
condition. Then you can create a file, or do 
whatever...

If it exists: it is renamed *immediately*, and 
is unavailable to all other apps, until you 
work on it and rename it *back*.

This way, the file is taken out of service 
*immediately* and (if you want to) can be back 
in service in milliseconds.

--------
The only problem with this is if the other apps
discover the file is missing, and attempt to
recreate it themselves.
0
ruthal (141)
6/14/2004 12:10:51 AM
On Sun, 13 Jun 2004 18:15:48 -0400, <cmoyaX@nospam.com> wrote:

>I think, though I may be wrong, that this is just the Open statement's
>classic behavior. I don't think there's a "pure VB" workaround. If you don't
>like the "2-step" approach (even using the super-fast FindFirstFile API) and
>you need something a little more honed then:
>1) Use the OpenFile API (or the MS recommened CreateFile API--- which is a
>misnomer it can behave as an "open file" function). Then use the API's for
>reading and writing binary data (it's not that hard).
>2) Switch to VB.NET. The File I/O routines allow for the fine-tuning that
>you seek.
>
Hangon a sec. I'm getting confused as to what Stefan wants to do here.
Once you open a file in Binary, i don't think another application can
get a handle to it anyway. If you open the file and do a Lof() on it,
then you will know if the file is a new file or not. That is all that
anyone (Stefan) may want to know. 
So even if opening in paranoid mode, ie: Open fpath for Binary Lock
ReadWrite, the file has either been deleted already, or it's there. 
I mean, just how confusing can a boolean get ? ;-) 

-- 

Regards, Frank
0
fajp1 (1575)
6/14/2004 12:43:12 AM
: Hmm. That's an interesting question. Lookup the OpenFile API in MSDN. I
: think it does exactly what you want.


Note however that OpenFile has a caveat ... "This function is provided only 
for compatibility with 16-bit versions of Windows. New applications should 
use the CreateFile function".

-- 

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.

0
6/14/2004 5:24:08 AM
It should work for Stefan if he specifies OPEN_EXISTING for 
dwCreationDisposition, and along with FILE_SHARE_READ and FILE_SHARE_WRITE 
for dwShareMode, perhaps also FILE_SHARE_DELETE which will allow him to 
automatically delete the file when it is closed (and 
FILE_FLAG_DELETE_ON_CLOSE is specified as dwFlagsAndAttributes (but only on 
NT systems). FILE_FLAG_WRITE_THROUGH (dwFlagsAndAttributes as well) may also 
be of value, as it instructs the OS to write-through any intermediate cache 
and go directly to disk.

-- 

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.


<cmoyaX@nospam.com> wrote in message 
news:40ccd21c$0$3011$61fed72c@news.rcn.com...
: I think, though I may be wrong, that this is just the Open statement's
: classic behavior. I don't think there's a "pure VB" workaround. If you 
don't
: like the "2-step" approach (even using the super-fast FindFirstFile API) 
and
: you need something a little more honed then:
: 1) Use the OpenFile API (or the MS recommened CreateFile API--- which is a
: misnomer it can behave as an "open file" function). Then use the API's for
: reading and writing binary data (it's not that hard).
: 2) Switch to VB.NET. The File I/O routines allow for the fine-tuning that
: you seek.
:
: "Stefan Mueller" <noemail@noemail.com> wrote in message
: news:caiik5$71k$1@news.eusc.inter.net...
: > Thanks for the code and you hint, but between the file test and the open
: > there is still a very very small time where another program can remove 
the
: > file and because I'm testing a software where several programs 
intensively
: > try to access the same files over several hours, it's sometimes 
possible,
: > that a program deletes a file between the file test and the open
: statement.
: >
: > I really think I have to find a solution to open a file for binary 
access
: > with a read/write lock which does not create an empty file if the file
: does
: > not exist anymore.
: >
: > Stefan
: >
: >
: > "Randy Day" <ruthal@sasktel.nex> wrote in message
: > news:40CC94AA.33119366@sasktel.nex...
: > > Stefan Mueller wrote:
: > > >
: > > > Yea, that's exactly what I tried to do. I opened the file with 'For
: > Input'
: > > > (if the file doesn't exist anymore no empty file will be created and 
I
: > get
: > > > an error which I can handle with 'On Error') and stored its size 
using
: > LOF.
: > > > Then I opened the file again with 'For Binary' and compared the 
size.
: > That
: > > > really works quite well, but there's still a problem.
: > > >
: > > > If the original file in the meantime has been removed and I 
therefore
: > > > created with the open a new empty file then this file can also be
: opened
: > by
: > > > another program which is also intensively opening files. Therefore I
: > used
: > > > 'Lock Read Write' so another program cannot open this file. But now,
: how
: > can
: > > > I delete this empty file? I need to close and kill the file and
: between
: > the
: > > > close and kill another program can !!and will!! open this empty 
file.
: > > >
: > > > I really think I only have one solution: Somehow to open a file for
: > binary
: > > > without creating an empty file if the file doesn't exist anymore.
: > >
: > > Sorry about the partial post - fat fingers hit the
: > > wrong keys.
: > >
: > > Try testing for the file without opening anything:
: > >
: > > Function FileExists(fname As String) As Boolean
: > > If Dir(fname) <> "" Then
: > >     FileExists = True
: > > Else
: > >     FileExists = False
: > > End If
: > > End Function
: > >
: > > - with thanks to whoever it was on this group
: > >   who posted this function originally!  :)
: >
: >
:
: 

0
6/14/2004 5:37:33 AM
Hi Frank ...

I think he's concerned that if he does open a file successfully, regardless 
of method, that between the time his code hits the Close and Kill lines that 
another app may have re-opened the file for its use. I read this as really 
being an issue of caching of commands, and the possible delay that may be 
introduced by the operating system when the Kill is requested.

-- 

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.


"Frank Adam" <fajp@xxxxoptushome.com.au> wrote in message 
news:tmspc09rb5kp4qml4hf9cajeib2773tbtj@4ax.com...
: On Sun, 13 Jun 2004 18:15:48 -0400, <cmoyaX@nospam.com> wrote:
:
: >I think, though I may be wrong, that this is just the Open statement's
: >classic behavior. I don't think there's a "pure VB" workaround. If you 
don't
: >like the "2-step" approach (even using the super-fast FindFirstFile API) 
and
: >you need something a little more honed then:
: >1) Use the OpenFile API (or the MS recommened CreateFile API--- which is 
a
: >misnomer it can behave as an "open file" function). Then use the API's 
for
: >reading and writing binary data (it's not that hard).
: >2) Switch to VB.NET. The File I/O routines allow for the fine-tuning that
: >you seek.
: >
: Hangon a sec. I'm getting confused as to what Stefan wants to do here.
: Once you open a file in Binary, i don't think another application can
: get a handle to it anyway. If you open the file and do a Lof() on it,
: then you will know if the file is a new file or not. That is all that
: anyone (Stefan) may want to know.
: So even if opening in paranoid mode, ie: Open fpath for Binary Lock
: ReadWrite, the file has either been deleted already, or it's there.
: I mean, just how confusing can a boolean get ? ;-)
:
: -- 
:
: Regards, Frank 

0
6/14/2004 5:41:55 AM
Quite right. The misnamed (IMO) "CreateFile" provides the same
functionality. I didn't want to confuse the guy by citing "CreateFile" and
having him just say "eh, that's not what I want" without lookup up the
documentation.


0
cmoyaX (98)
6/14/2004 5:49:32 AM
On Sun, 13 Jun 2004 15:21:54 +0200, "Stefan Mueller"
<noemail@noemail.com> wrote:

>I'd like to open a file for binary access
>  Open "C:\Test\myfile.bin" For Binary Lock Read Write As #1
>
>Unfortunately if the file does not exist an empty file is created (Visual
>Basic Documentation: If the file specified by pathname doesn't exist, it is
>created when a file is opened for Append, Binary, Output, or Random modes).
>
>Today before opening the file for binary access I check if the file exists.
>But I experienced situations where the file during the file check existed
>and just before the opening of the file it has been removed by another
>programm.
>
>Is there really no possibility to open a file for binary access only if the
>file exists and else to get an error message which I can handle with On
>Error?

I think that you might be better off looking again at the general
approach.

Why would another program zap the file ?
Is that other program yours ?
What will the other program do if it finds the file locked ?
What will your App do if it finds the file is locked ?

The general solution for dealing with the type of problem that I think
you are having, is to rename the file (ideally the sender creates
closes and then renames the file)
0
erewhon (1218)
6/14/2004 6:21:57 AM
On Sun, 13 Jun 2004 11:53:46 -0600, Randy Day <ruthal@sasktel.nex>
wrote:
<snip>

>Try testing for the file without opening anything:
>
>Function FileExists(fname As String) As Boolean
>If Dir(fname) <> "" Then
>    FileExists = True
>Else
>    FileExists = False
>End If
>End Function
>
>- with thanks to whoever it was on this group 
>  who posted this function originally!  :)

Don't thank them for that Randy
- it is dangerous code
- using Dir() like that will muck up any other Dir() loops
The general method is to use :-

Function FileExists(Fle$) As Boolean
    Dim Q%
    On Error Resume Next
    Q = GetAttr(Fle$)
    If Err = 0 Then
       If (Q And vbDirectory) = 0 Then
          FileExists = True
       End If
    End If
    Err.Clear
End Function


0
erewhon (1218)
6/14/2004 6:25:41 AM
On Sun, 13 Jun 2004 23:59:51 +0200, "Stefan Mueller"
<noemail@noemail.com> wrote:

>Thanks for the code and you hint, but between the file test and the open
>there is still a very very small time where another program can remove the
>file and because I'm testing a software where several programs intensively
>try to access the same files over several hours, it's sometimes possible,
>that a program deletes a file between the file test and the open statement.
>
>I really think I have to find a solution to open a file for binary access
>with a read/write lock which does not create an empty file if the file does
>not exist anymore.

That or try to rename the file to something else.
0
erewhon (1218)
6/14/2004 6:28:05 AM
Yea, that's exactly my problem.
I can figure out if the just opened file didn't exist before the open for
binary access. But now I can't delete the just created empty file because to
kill the file I need to close it first and between the close and the kill
command another program can and will use (I did tests over several hours)
the just created empty file.

Stefan


"Randy Birch" <rgb_removethis@mvps.org> wrote in message
news:DUazc.5616$sjq1.2850@news04.bloor.is.net.cable.rogers.com...
> Hi Frank ...
>
> I think he's concerned that if he does open a file successfully,
regardless
> of method, that between the time his code hits the Close and Kill lines
that
> another app may have re-opened the file for its use. I read this as really
> being an issue of caching of commands, and the possible delay that may be
> introduced by the operating system when the Kill is requested.
>
> -- 
>
> Randy Birch
> MVP Visual Basic
> http://vbnet.mvps.org/
> Please respond only to the newsgroups so all can benefit.
>
>
> "Frank Adam" <fajp@xxxxoptushome.com.au> wrote in message
> news:tmspc09rb5kp4qml4hf9cajeib2773tbtj@4ax.com...
> : On Sun, 13 Jun 2004 18:15:48 -0400, <cmoyaX@nospam.com> wrote:
> :
> : >I think, though I may be wrong, that this is just the Open statement's
> : >classic behavior. I don't think there's a "pure VB" workaround. If you
> don't
> : >like the "2-step" approach (even using the super-fast FindFirstFile
API)
> and
> : >you need something a little more honed then:
> : >1) Use the OpenFile API (or the MS recommened CreateFile API--- which
is
> a
> : >misnomer it can behave as an "open file" function). Then use the API's
> for
> : >reading and writing binary data (it's not that hard).
> : >2) Switch to VB.NET. The File I/O routines allow for the fine-tuning
that
> : >you seek.
> : >
> : Hangon a sec. I'm getting confused as to what Stefan wants to do here.
> : Once you open a file in Binary, i don't think another application can
> : get a handle to it anyway. If you open the file and do a Lof() on it,
> : then you will know if the file is a new file or not. That is all that
> : anyone (Stefan) may want to know.
> : So even if opening in paranoid mode, ie: Open fpath for Binary Lock
> : ReadWrite, the file has either been deleted already, or it's there.
> : I mean, just how confusing can a boolean get ? ;-)
> :
> : -- 
> :
> : Regards, Frank
>


0
noemail10 (353)
6/14/2004 7:40:02 AM
"Stefan Mueller" <noemail@noemail.com> skrev i en meddelelse
news:cahk91$sd$1@news.eusc.inter.net...
> I'd like to open a file for binary access
>   Open "C:\Test\myfile.bin" For Binary Lock Read Write As #1

Have you considered NOT using "Write" ? Of course the file is
created if you use "Write"

-- 
/\ preben nielsen
\/\ prel@post.tele.dk


0
prel (77)
6/14/2004 8:02:49 AM
Good idea, guys.
I'm really thinking about the solution to rename the file.

Which command to rename the file would you propose? The command 'Name'?

Stefan

"J French" <erewhon@nowhere.com> wrote in message
news:40cd4556.2027482@news.btclick.com...
> On Sun, 13 Jun 2004 23:59:51 +0200, "Stefan Mueller"
> <noemail@noemail.com> wrote:
>
> >Thanks for the code and you hint, but between the file test and the open
> >there is still a very very small time where another program can remove
the
> >file and because I'm testing a software where several programs
intensively
> >try to access the same files over several hours, it's sometimes possible,
> >that a program deletes a file between the file test and the open
statement.
> >
> >I really think I have to find a solution to open a file for binary access
> >with a read/write lock which does not create an empty file if the file
does
> >not exist anymore.
>
> That or try to rename the file to something else.


0
noemail10 (353)
6/14/2004 8:03:39 AM
Do you mean that I should use CreateFile instead of OpenFile for opening a
file for binary access?

Stefan

<cmoyaX@nospam.com> wrote in message
news:40cd3c71$0$3032$61fed72c@news.rcn.com...
> Quite right. The misnamed (IMO) "CreateFile" provides the same
> functionality. I didn't want to confuse the guy by citing "CreateFile" and
> having him just say "eh, that's not what I want" without lookup up the
> documentation.
>
>


0
noemail10 (353)
6/14/2004 8:08:22 AM
"Write" is for the "Lock" part and not for the access mode.
And also the Visual Basic Documentation says: If the file specified by
pathname doesn't exist, it is created when a file is opened for Append,
Binary, Output, or Random modes).

Stefan

"preben nielsen" <prel@post.tele.dk> wrote in message
news:40cd5bac$0$189$edfadb0f@dread12.news.tele.dk...
>
> "Stefan Mueller" <noemail@noemail.com> skrev i en meddelelse
> news:cahk91$sd$1@news.eusc.inter.net...
> > I'd like to open a file for binary access
> >   Open "C:\Test\myfile.bin" For Binary Lock Read Write As #1
>
> Have you considered NOT using "Write" ? Of course the file is
> created if you use "Write"
>
> -- 
> /\ preben nielsen
> \/\ prel@post.tele.dk
>
>


0
noemail10 (353)
6/14/2004 8:13:34 AM
On Mon, 14 Jun 2004 10:03:39 +0200, "Stefan Mueller"
<noemail@noemail.com> wrote:

>Good idea, guys.
>I'm really thinking about the solution to rename the file.
>
>Which command to rename the file would you propose? The command 'Name'?

I would try that out, wrapped in a little On Error Resume Next it
should be fine

However, the API MoveFileEx might be more to your taste

MOVEFILE_REPLACE_EXISTING might be handy

MoveFile allows you to shove the file onto a different drive, which
might be useful.

0
erewhon (1218)
6/14/2004 11:11:44 AM
Dude, go to MSDN and look up the documentation for OpenFile. Decide for
yourself.

"Stefan Mueller" <noemail@noemail.com> wrote in message
news:cajm93$ef8$1@news.eusc.inter.net...
> Do you mean that I should use CreateFile instead of OpenFile for opening a
> file for binary access?
>
> Stefan
>
> <cmoyaX@nospam.com> wrote in message
> news:40cd3c71$0$3032$61fed72c@news.rcn.com...
> > Quite right. The misnamed (IMO) "CreateFile" provides the same
> > functionality. I didn't want to confuse the guy by citing "CreateFile"
and
> > having him just say "eh, that's not what I want" without lookup up the
> > documentation.
> >
> >
>
>


0
cmoyaX (98)
6/14/2004 12:13:41 PM
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/openfile.asp
Then use the VB API Viewer add-in to access the API. Perhaps someone has
some code for you to cut & paste.

<cmoyaX@nospam.com> wrote in message
news:40cd967a$0$3030$61fed72c@news.rcn.com...
> Dude, go to MSDN and look up the documentation for OpenFile. Decide for
> yourself.
>
> "Stefan Mueller" <noemail@noemail.com> wrote in message
> news:cajm93$ef8$1@news.eusc.inter.net...
> > Do you mean that I should use CreateFile instead of OpenFile for opening
a
> > file for binary access?
> >
> > Stefan
> >
> > <cmoyaX@nospam.com> wrote in message
> > news:40cd3c71$0$3032$61fed72c@news.rcn.com...
> > > Quite right. The misnamed (IMO) "CreateFile" provides the same
> > > functionality. I didn't want to confuse the guy by citing "CreateFile"
> and
> > > having him just say "eh, that's not what I want" without lookup up the
> > > documentation.
> > >
> > >
> >
> >
>
>


0
cmoyaX (98)
6/14/2004 12:25:07 PM
J French wrote:

[snip]

> Don't thank them for that Randy
> - it is dangerous code
> - using Dir() like that will muck up any other Dir() loops
> The general method is to use :-
> 
> Function FileExists(Fle$) As Boolean
>     Dim Q%
>     On Error Resume Next
>     Q = GetAttr(Fle$)
>     If Err = 0 Then
>        If (Q And vbDirectory) = 0 Then
>           FileExists = True
>        End If
>     End If
>     Err.Clear
> End Function

Noted. Thanks for the warning!
0
ruthal (141)
6/14/2004 10:06:06 PM
What's about the speed between CreateFile, ReadFile and WriteFile compared
with Open, Get and Put?

Stefan


<cmoyaX@nospam.com> wrote in message
news:40cd9927$0$3040$61fed72c@news.rcn.com...
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/openfile.asp
> Then use the VB API Viewer add-in to access the API. Perhaps someone has
> some code for you to cut & paste.
>
> <cmoyaX@nospam.com> wrote in message
> news:40cd967a$0$3030$61fed72c@news.rcn.com...
> > Dude, go to MSDN and look up the documentation for OpenFile. Decide for
> > yourself.
> >
> > "Stefan Mueller" <noemail@noemail.com> wrote in message
> > news:cajm93$ef8$1@news.eusc.inter.net...
> > > Do you mean that I should use CreateFile instead of OpenFile for
opening
> a
> > > file for binary access?
> > >
> > > Stefan
> > >
> > > <cmoyaX@nospam.com> wrote in message
> > > news:40cd3c71$0$3032$61fed72c@news.rcn.com...
> > > > Quite right. The misnamed (IMO) "CreateFile" provides the same
> > > > functionality. I didn't want to confuse the guy by citing
"CreateFile"
> > and
> > > > having him just say "eh, that's not what I want" without lookup up
the
> > > > documentation.
> > > >
> > > >
> > >
> > >
> >
> >
>
>


0
noemail10 (353)
6/14/2004 11:35:34 PM
It stands to reason that API's in general are faster. VB's Open/Get/Put are
most likely just wrappers around the CreateFile/ReadFile/WriteFile API...
albeit wrapped in such a way as to maintain the B.A.S.I.C. syntax (BASIC's
File I/O syntax goes way back). Though, you'll probably never notice the
difference in the real-world and it would depend on what exactly you're
doing.

"Stefan Mueller" <noemail@noemail.com> wrote in message
news:calcji$rv5$1@news.eusc.inter.net...
> What's about the speed between CreateFile, ReadFile and WriteFile compared
> with Open, Get and Put?
>
> Stefan
>
>
> <cmoyaX@nospam.com> wrote in message
> news:40cd9927$0$3040$61fed72c@news.rcn.com...
> >
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/openfile.asp
> > Then use the VB API Viewer add-in to access the API. Perhaps someone has
> > some code for you to cut & paste.
> >
> > <cmoyaX@nospam.com> wrote in message
> > news:40cd967a$0$3030$61fed72c@news.rcn.com...
> > > Dude, go to MSDN and look up the documentation for OpenFile. Decide
for
> > > yourself.
> > >
> > > "Stefan Mueller" <noemail@noemail.com> wrote in message
> > > news:cajm93$ef8$1@news.eusc.inter.net...
> > > > Do you mean that I should use CreateFile instead of OpenFile for
> opening
> > a
> > > > file for binary access?
> > > >
> > > > Stefan
> > > >
> > > > <cmoyaX@nospam.com> wrote in message
> > > > news:40cd3c71$0$3032$61fed72c@news.rcn.com...
> > > > > Quite right. The misnamed (IMO) "CreateFile" provides the same
> > > > > functionality. I didn't want to confuse the guy by citing
> "CreateFile"
> > > and
> > > > > having him just say "eh, that's not what I want" without lookup up
> the
> > > > > documentation.
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>


0
cmoyaX (98)
6/15/2004 1:01:38 AM
"Stefan Mueller" <noemail@noemail.com> wrote in message
news:calcji$rv5$1@news.eusc.inter.net...
> What's about the speed between CreateFile, ReadFile and WriteFile
compared
> with Open, Get and Put?
>
> Stefan
>
>

Not sure which part of this thread to poke this into. Here is a boiled
down version of using the File API which I think can do what you want.
No error handlers or other such niceties included, and not much testing,
either.

Option Explicit

Const OPEN_EXISTING = 3
Const GENERIC_READ = &H80000000
Const GENERIC_WRITE = &H40000000
Const READ_WRITE = GENERIC_READ Or GENERIC_WRITE

Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA"
( _
    ByVal lpFileName As String, _
    ByVal dwDesiredAccess As Long, _
    ByVal dwShareMode As Long, _
    ByVal lpSecurityAttributes As Any, _
    ByVal dwCreationDisposition As Long, _
    ByVal dwFlagsAndAttributes As Long, _
    ByVal hTemplateFile As Long) As Long

Private Declare Function ReadFile Lib "kernel32" ( _
    ByVal hFile As Long, _
    lpBuffer As Any, _
    ByVal nNumberOfBytesToRead As Long, _
    lpNumberOfBytesRead As Long, _
    ByVal lpOverlapped As Any) As Long

Private Declare Function WriteFile Lib "kernel32" ( _
    ByVal hFile As Long, _
    lpBuffer As Any, _
    ByVal nNumberOfBytesToWrite As Long, _
    lpNumberOfBytesWritten As Long, _
    ByVal lpOverlapped As Any) As Long

Private Declare Function CloseHandle Lib "kernel32" ( _
    ByVal hObject As Long) As Long

Public Function OpenFile(FilePath As String) As Long
    'Open the file if it exists with exclusive read/write access
    'returns file handle, or -1 on failure
    OpenFile = CreateFile(FilePath, READ_WRITE, 0, _
        ByVal 0&, OPEN_EXISTING, 0, 0)
End Function

Public Function ReadBytes(FileHandle As Long, Buffer() As Byte) As Long
    Dim nRead As Long
    ReadFile FileHandle, Buffer(0), UBound(Buffer) + 1, _
        nRead, ByVal 0&
    ReadBytes = nRead
End Function

Public Function WriteBytes(FileHandle As Long, Buffer() As Byte) As Long
    Dim nWritten As Long
    WriteFile FileHandle, Buffer(0), UBound(Buffer) + 1, _
        nWritten, ByVal 0&
    WriteBytes = nWritten
End Function

Public Sub CloseFile(FileHandle As Long)
    CloseHandle FileHandle
End Sub




0
6/15/2004 3:42:02 AM
I'm just a newbe, but couldn't you make a copy of the file first then set
the path name to the copy and check that file.  If you're not really writing
to the file then no biggie.  Is this just a one time deal ?

Mark


"Stefan Mueller" <noemail@noemail.com> wrote in message
news:cajmir$eii$1@news.eusc.inter.net...
> "Write" is for the "Lock" part and not for the access mode.
> And also the Visual Basic Documentation says: If the file specified by
> pathname doesn't exist, it is created when a file is opened for Append,
> Binary, Output, or Random modes).
>
> Stefan
>
> "preben nielsen" <prel@post.tele.dk> wrote in message
> news:40cd5bac$0$189$edfadb0f@dread12.news.tele.dk...
> >
> > "Stefan Mueller" <noemail@noemail.com> skrev i en meddelelse
> > news:cahk91$sd$1@news.eusc.inter.net...
> > > I'd like to open a file for binary access
> > >   Open "C:\Test\myfile.bin" For Binary Lock Read Write As #1
> >
> > Have you considered NOT using "Write" ? Of course the file is
> > created if you use "Write"
> >
> > --
> > /\ preben nielsen
> > \/\ prel@post.tele.dk
> >
> >
>
>


0
6/25/2004 7:06:57 AM
Reply:

Similar Artilces:

open file in c / create if file doesn't exist
Hi everyone! I have a problem with trying to open a file in C. The following line in my code is suppoed to open a specified file if it exists and create a new one with this name if one doesn't exist: if ((shfd = open(argv[2], O_CREAT | O_RDWR, 0644)) < 0) my_error("open failed"); If I try to open a file that doesn't exist I get an error: Bus error And when it creates a file it sets permissions to -rw------ instead of -rw-r--r-- as I would hope... Is there something I'm not getting about how O_CREATE works?... However, if I try to open existing file that is no...

How can I creat a file if the file doesn't exit?
int main( ) { string str; string filename; fstream outfile; cout<<"Input the file name you will save in:"<<endl; getline(cin,filename); outfile.open(filename.c_str() ); //cin.clear(); //清空流 cout<<"Please input your text....."<<endl; getline(cin,str); outfile<<str; outfile.close(); return 0; } when it request me to input the filename, if the filename I input is exit, the program work normally. But if the file doesn't exit, it can't work . how can i creat a new file when it doesn't exit? Thanks~ ^_^# { Ple...

How to determine whether a file doesn't exist or doesn't have enough permissions
Hello everone, I am stuck in determining whether a file does not exist or does not have enough permissions so that access to this file is denied?". I am using java.io.File.exists() or java.io.File.canRead() methods to check this but both of them just return false in both above mentioned cases. In the documentation however its mentioned that these method throw SecurityException - If a security manager exists and its SecurityManager.checkRead(java.lang.String) method denies read access to the file. But then problem is to write a security manager which denies read access if the file does not...

'cat file' but only if 'file' exist
I'm trying to run 'cat *.x' only if *.x files exist. What is the cleanest way of doing this? I'm doing it by shopt -s nullglob for i in *.x; do cat $i; done but this is aweful typing. -- William Park, Open Geometry Consulting, <opengeometry@yahoo.ca> No, I will not fix your computer! I'll reformat your harddisk, though. On 2004-06-09, William Park wrote: > I'm trying to run 'cat *.x' only if *.x files exist. What is the > cleanest way of doing this? I'm doing it by > shopt -s nullglob > for i in *.x; do cat $i; done > but this is aweful typing. set -- *.x [ -f "$1" ] && cat -- *.x -- Chris F.A. Johnson http://cfaj.freeshell.org/shell =================================================================== My code (if any) in this post is copyright 2004, Chris F.A. Johnson and may be copied under the terms of the GNU General Public License 2004-06-9, 06:26(+00), William Park: > I'm trying to run 'cat *.x' only if *.x files exist. What is the > cleanest way of doing this? I'm doing it by > shopt -s nullglob > for i in *.x; do cat $i; done > but this is aweful typing. zsh -c 'cat ./*.x' With bash: shopt -s nullglob files=(./*.x) if (( ${#files[@]} > 0 )); then cat "${files[@]}" else printf >&2 '%s\n' "${0##*/}: no *.x files" false fi You could also do: c...

Creating a file that doesn't exist
Hello, I was wondering if it is possible to create a file if it doean't exist. I am using fstream and writing in and out a binary file. I check to see if the file is opened. if it doesn't get opened, i want to create the file. I was wondering if this can be done. This is the code i have for opening the file: fstream rfile("names.db", ios::binary| ios::in | ios::out); if ( !rfile ) { cerr << "Could not open file 'names.db'\n"; } I am hoping to put the creating of the file after the cerr. i hope someone can help me out with this. thanks. ...

File::open and File.open
What exactly is the difference between these? :: is a class method while is an instance method??? If that is so, could someone clarify this with more detail? I use File.open, but File::open works too. However sometimes, this is not the case which adds to my confusion :) For example, I can only do Digest::MD5.new() and not Digest.MD5.new() why is that? I don't fully understand OO programming... perhaps this is my problem. Thank you for your time. -- Posted via http://www.ruby-forum.com/. Robert Klemme schrieb: > Brad Tilley wrote: >> What exactly is the difference betwe...

file.read() doesn't read the whole file
Hi, >>> snapdir = './mango.txt_snaps' >>> snap_cnt = 1 >>> block = 0 >>> import os >>> os.chdir('/mnt/gfs_local') >>> snap = open(snapdir + '/snap%s/%s' % (repr(snap_cnt), repr(block)),'r') >>> snap.read() 'dfdfdgagdfgdf\ngdgfadgagadg\nagafg\n\nfs\nf\nsadf\n\nsdfsdfsadf\n' >>> snapdir + '/snap%s/%s' % (repr(snap_cnt), repr(block)) './mango.txt_snaps/snap1/0' The above code works fine and it reads the whole file till EOF. But when this method is used in a different s...

Reading a file FileReader, doesn't read a file
Hello I wanted to write a simple program that gets a string from a file. But i don't know where to put the file that i could read it. I puted the plik.txt file in the package where my Main class is. I UseNetBeans if that makes a diference. Here is my code. package czytaniezpliku import java.io.*; public class Main { public static void main(String args[]) { try { String wejscie; BufferedReader br =3D new BufferedReader(new FileReader("plik.txt")); //FileReader we =3D new FileReader("pliki/ plik1.txt"); ...

file.encoding doesn't apply to file.write?
I noticed in python2.3 printing unicode to an appropriate terminal actually works. But using sys.stdout.write doesn't. Ex: Python 2.3.4 (#2, May 29 2004, 03:31:27) [GCC 3.3.3 (Debian 20040417)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> sys.stdout.encoding 'UTF-8' >>> u=u'\u3053\u3093\u306b\u3061\u308f' >>> print u >>> sys.stdout.write(u) Traceback (most recent call last): File "<stdin>", line 1, in ? UnicodeEncodeError: 'ascii...

File::Copy works, File::NCopy doesn't
I have a situation where I invoke File::Copy and File::NCopy with identical arguments - I am attempting to copy a file from one network path to another, something like copy( "\\\\$somepath\\foo\\bar.txt", "\\\\$someotherpath\\foo\\bar.txt" ); File::Copy works fine, but File::NCopy says "No such file or directory". Can NCopy's copy not handle network paths? (This is ActiveState Perl 5.8.7 for WinXP). -- Christopher Benson-Manica | I *should* know what I'm talking about - if I ataru(at)cyberspace.org | don't, I need to know. Flames welcome. C...

File::MMagic doesn't recognize rar file
Hello, File::MMagic doesn't seem to recognize rar files. (tar is ok). The machine is running Debian Etch. Here is the perl version: $ perl -v This is perl, v5.8.8 built for i486-linux-gnu-thread-multi Copyright 1987-2006, Larry Wall .... Here is the version of File::MMagic: $ head -3 /usr/share/perl5/File/MMagic.pm # File::MMagic # # $Id: MMagic.pm 198 2006-01-30 05:24:17Z knok $ $ Here is my script: ############################## Script starts ############################## #!/usr/bin/perl -w use strict; use File::MMagic; my $magic = new File::MMagic; my $type; foreach my $file ...

File Contents Won't Update Until File is Opened
Hey, I ran into this problem before, but cant remember if/how I solved it. Anyways, I'm overwriting a file (objfun.m) based on what the user inputs. I'm using: fid=fopen('objfun.m','w'); A bunch complex parsing stuff hapens here.... fclose(fid); Then the new contents of objfun.m are read and used in my program. The problem is objfun.m is not actually changed unless I manually open it. What happens is when I read objfun.m I still get the old contents. If I double click it (manually opening it),I see the new stuff is there. Now, by opening it, it has been changed and I can read the new contents. It's as if the file is not properly updated for some reason until it is manually opened. Is there way to fix this or a workaround? Thanks Remembered the solution. I must use clear functions to update the contents. Thanks. ...

Open folder, read file, close file, open new folder, read file close file etc....
Hello, My current directory has several folders within it. Each folder has the same type of file within it. How do i go from the current directory, into one of the folders, edit the file, then come out of the folder, then go into another folder, edit a file then come out of the folder then into a new one etc etc etc. If this does not make sense i apologise and will try to explain my problem a little better. Any help would be much appreciated. Cheers, Phil Phil: I'm not sure it makes sense. Personally I use the mouse and keyboard for doing this. Were you thinking of something else?...

atomically opening a file for writing that doesn't already exist?
Are there any intentions in the upcoming revision to the C++ standard to solve the problem that makes it impossible in C++ to *atomically* open a file for writing that does not already exist? (I understand that an early draft of the C++ standard had a mode noreplace, but that did not make it into the standard.) Attempts to first check for existence of the file and then open it suffer from a "Time of Check, Time of Use" (or TOCTOU) vulnerability. For example: ifstream fi("foo.txt");// attempt to open as input file if (!fi) { // file doesn't exist; so it's safe to create it and write to it ofstream fo("foo.txt"); // can now write to fo, e.g., fo << "Some output" << endl; ... } else // file exists; close and handle error { fi.close(); // handle error } On a shared multitasking system there is a window of opportunity between the first call of open and the second call for a malicious attacker to, for example, create a link with the given filename to an existing file, so that the existing file is overwritten by the second call of open and the subsequent writing to the file. See: https://www.securecoding.cert.org/confluence/display/cplusplus/FIO01-A.+Do+not+make+assumptions+about+open%28%29+and+file+creation for more information and possible solutions that are not standard C++. Thanks, Fred Long CERT Coordination C...

How to create PC File Description File(.FDF) for Client Access file transfer utility?
Hello Friends, I want to know how can i create PC File Description file (.FDF) that we give in File Transfer Utility of Client Access, while transfering any file from PC to AS400. What are the parameters of .FDF file and how can i create one to describe my PC file that is to be transfered? I would be grateful if you can guide me to some manual in which i can get this. Thanks in Advance for yr help in this regard. kind regards, Umer Assuming the file exists on the as400, use CA to download the file first and select create FDF option. If not, download any file and select FDF and look at its definition. I remember it being pretty basic, but I can't recall the exact syntax. On Mon, 15 Dec 2003 23:25:14 -0800, Umer wrote: > Hello Friends, > I want to know how can i create PC File Description file (.FDF) > that we give in File Transfer Utility of Client Access, while > transfering any file from PC to AS400. What are the parameters of .FDF > file and how can i create one to describe my PC file that is to be > transfered? I would be grateful if you can guide me to some manual in > which i can get this. > Thanks in Advance for yr help in this regard. > > kind regards, > Umer > "Umer" wrote: > I want to know how can i create PC File Description file (.FDF) > that we give in File Transfer Utility of Client Access, while > transfering any file from PC to AS400. What are the parameters of .FDF > f...

Drift file/Log files don't get created
Hi,=20 =20 I think I should start off by saying I'm very new to NTP, so if the answer to this seems stupidly obvious to you, it's probably correct. Please let me know of any other information you people would find useful in helping me out. =20 I've installed the NTPD on a windows 2003 server (I downloaded the installer GUI from the Meinberg site). The ntp.conf file has the following lines: =20 server x.x.x.x prefer #<-- this is the IP of a GPS source. It gets recognized by ntpq -p as a Stratum 1 logconfig =3Dall logfile "C:\Program Files\NTP\etc\ntp.log" driftfile "C:\ Program Files\NTP\etc\ntp.drift" statsdir "C:\ Program Files\NTP\etc\ntpstats" =20 No files or folders are written anywhere, even after overnight tests. Are these commands even supposed to work under a Windows environment?=20 =20 Thanks! =20 PS. I've also got problems involving a large offset but I'd like to address these simpler ones first. =20 Derek Flake Video Networks (613) 785-7099 derek.flake@bell.ca =20 _______________________________________________ questions mailing list questions@lists.ntp.isc.org https://lists.ntp.isc.org/mailman/listinfo/questions derek.flake@bell.ca wrote: > installer GUI from the Meinberg site). The ntp.conf file has the > following lines: > > server x.x.x.x prefer #<-- this is the IP of a GPS > source. It gets recognized by ntpq -p as a Stratum 1 > > logconfig =all > > l...

How to create new python file with increament number, if doesn't exist?
hi, I want to create a new python file like 'data0.0.5', but if it is alread= y exist then it should create 'data0.0.6', if it's also exist then next lik= e 'data0.0.7'. I have done, but with range, please give me suggestion so th= at I can do it with specifying range. I was trying this way and it's working also.. i =3D 0 for i in range(100): try: with open('Data%d.%d.%d.json'%(0,0,i,)): pass continue except IOError: edxCorrectDataFile =3D file('Data%d.%d.%d.json'%(0,0,i,), 'a+') break But here I have defined range 100, Is it possible without range it create m= any required files? Thanks On Mon, 27 May 2013 02:27:59 -0700, Avnesh Shakya wrote: > I want to create a new python file like 'data0.0.5', but if it is > already exist then it should create 'data0.0.6', if it's also exist > then next like 'data0.0.7'. I have done, but with range, please give > me suggestion so that I can do it with specifying range. Try and put your description into the sequence of instructions you want the computer follow. For this problem, my sequence of instructions would be: 1) Find the highest numbered existing file that matches the filename data0.0.[number] 2) Create a new file that is one number higher. Now the solution is easy. Find the list of filenames in the directory that...

Program to open a file in binary, skip X bytes and write the rest of the file to a new file
How would I approach this? I cannot store the entire file in memory (they are 30GB+) but I need to skip the first 292 bytes and write the rest to a new file. Thanks, Scott scad wrote: > How would I approach this? I cannot store the entire file in memory > (they are 30GB+) but I need to skip the first 292 bytes and write the > rest to a new file. 1. Open the file to read (file_1) 1.a If file_1 in bad state, report and exit. 2. Counter = number of bytes to skip 3. While counter > 0 and not the end of file_1 read file_1 3.a. If file_1 in bad sta...

Tcl 8.6 unexpected 'file exists'
I have a proc which takes a full path argument for a file. (one of the items returned from a glob) roughly: proc handlefile {path} { #puts stdout [file normalize $path] set fsize [file size $path] #...etc } Strangely... a particular file has problems with the above. The 'file size' call returns: could not read "/usr/local/xxx/www/yyy/Newsletter/050609/~ $sueme220509.htm" no such file or directory The 'file normalize' output is "/usr/local/virtual1/hosting/base/yy/ yyy/yyy/www/Newsletter/050609/~$sueme220509.htm" Both these paths are valid, and equivalent due to some soft symlinking - and both work just fine in an interactive tclsh with 'file size' returning a size and 'file exists' returning 1. The heisenbuggish thing is - that the mere act of using puts to display the normalized path (without actually using the normalized value anywhere); causes the problem to disappear. i.e uncommenting the 2nd line in the proc above causes file size to work as expected. I'm assuming this is a bug - but at this stage I don't know if the ~ or $ characters are relevant or if it just happened to occur on this strangely named file for some other reason. This problem occurs on FreeBSD with a Tcl 8.5.b1 checked out in january - and also with 8.6b1.1 from 2009-06-14 The bug doesn't occur when I use an 8.5a4 tclkit I'll report a bug for it if it turns out to be a new one - but I just thought I'd throw ...

opening file
Hello, This really drives me nuts. Im opening an input file, and Im testing if it was open successfully. Thats it! I know that the file that Im trying to open DOES NOT exist but Im getting NO error message. No matter what name I enter I get 'file opened successfully" Any clues? Thanks! #include <iostream.h> #include <stdlib.h> #include <stdio.h> #include <fstream.h> int main() { ifstream infile; char file_name[16]; printf("\nEnter file name: "); cin>>file_name; infile.open(file_name); if (infile.fail()) ...

SBCL: couldn't duplicate file descriptor: Too many open files
Hello, From time to time I get the following error "couldn't duplicate file descriptor: Too many open files". I am using SBCL 1.0.54 on Linux. Until now I could not find the cause of this error. Is there some internal facility in SBCL that could tell me something about the file descriptors in use ? The error must be caused by some resources that are not freed. If I knew what are those many open files, it would be easy to correct my mistake. Thanks. Thibault Langlois <thibault.langlois@gmail.com> writes: > Hello, > > From time to time I get the following error "couldn't duplicate > file descriptor: Too many open files". I am using SBCL 1.0.54 on > Linux. > > Until now I could not find the cause of this error. > > Is there some internal facility in SBCL that could tell me something > about the file descriptors in use ? The error must be caused by some > resources that are not freed. If I knew what are those many open > files, it would be easy to correct my mistake. Use WITH-OPEN-FILE instead of OPEN. -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}. On Saturday, September 22, 2012 5:21:10 PM UTC+1, informatimago wrote: > Thibault Langlois <thibault.langlois@gmail.com> writes: > > > > > Hello, > > > > > > From time to time I get the follow...

Cannot create a file when that file already exists
I built a dummy Win32 Smart Device application from the Visual Studio 2005 wizard and upon deploying the application to the real Pocket PC device connected with ActiveSync 4.0, I got the following error message in the output console: "Cannot create a file when that file already exists". I had this error even the first time I deployed the application; thus it is not a problem because of a file I am trying to deploy that already exists. I did the same test on the Pocket PC 2003 emulator and everything works fine. Do you know to which file the error message is referring to? ...

create a zip file with existing files in it
I try the zip example described in the doc. It worked that way. But now I want to add existing files to a new created zip. first the code <code> void OBApp::Test () { wxFFileOutputStream out(_T("C:\\test.zip")); wxZipOutputStream zip(out); wxTextOutputStream txt(zip); // ?? wxFileInputStream strFile("C:\\autoexec.bat"); wxString sep(wxFileName::GetPathSeparator()); zip.PutNextEntry(_T("C:\\autoexec.bat")); txt << _T("Some text for entry1.txt\n"); zip.PutNextEn...

Modify a file's date & time without modifying the file (or opening it)
Just in case you ever need this. We run a lot of monitor programs that look at the date and time of a file to see if a particular application is alive and well. In the past we had been simply writing another line to the file each time the application program cycled. This (of course) meant that the file grew proportional to how often the application cycled. With this routine, the file never grows, but still provides the desired results. Hope you can find a use for it. Lee (Obviously this is Object Rexx on Windows) /* touchfile.rex */ call SysCls parse arg myfile path = filespec(&#...

Web resources about - How to open a file for binary access without creating an empty file if the file doesn't exist - comp.lang.basic.visual.misc

Resources last updated: 3/24/2016 11:40:52 PM