Sorry, Here is the working verb. FindFirstFile will return the file information for an open file.

Session 1:

   h=:1!:21<'xxx'
   h
43669440


Session 2:

   load'bigfiles'
   load'dir'
   fdir 'xxx'
+---+-----------------+-+---+------+
|xxx|2008 12 1 7 30 11|0|rw-|-----a|
+---+-----------------+-+---+------+
    bfsize_jbf_ 'xxx'
+--+---------------------------------------------------------------------------------+
|32|The process cannot access the file because it is being used by another process. |
+--+---------------------------------------------------------------------------------+

   load 'C:\Users\DM\j602-user\temp\18.ijs'
   fffsize'xxx'
0

Session 1:
   (100#'a') 1!:2 h

Session 2:
   fffsize'xxx'
0
   1!:4 <'xxx'
100
   fffsize'xxx'
100

Session 1:
   (100#'a') 1!:3 h

Session 2:
   fffsize'xxx'
100
   1!:4 <'xxx'
200
   fffsize'xxx'
200

Clearly, 1!:4 is doing something to synchronize the file size that FindFirstFile does not do.

For now, adding a 1!:4 to the start of fffsize would be a 64 bit workaround.

---
NB. 18.ijs

FindFirstFile=: 'kernel32 FindFirstFileA i *c *'&cd
FindClose=: 'kernel32 FindClose i i'&cd

K32=: 2^32
findd=:318$'a'
ffsize=:28+i.8
INVALID_HANDLE_VALUE=: _1
ds0=:{.a.
int=: 16{.1 tobin 8888888 NB. get header for integer

tobin=: 3!:1
frombin=: 3!:2

ctoi=: 3 : 0
frombin int,4{.!.ds0 y
)

b32to64=: 3 : 0
K32#.|:K32&|y
)

NB. =========================================================
NB.*fffsize v get file size using windows API
NB. form: fffsize file_path_name
fffsize=: 3 : 0
'fh ft fv'=. FindFirstFile y;findd
if. INVALID_HANDLE_VALUE~:fh do.
 r=.b32to64 ctoi"1]2 4$ffsize{fv
 FindClose fh
else.
 r=.''
end.
r
)

--

David Mitchell


Don Guinn wrote:
Here is the problem: Given a file in the current directory "xxx" is opened
in one J session then tried to get it's size using bigfiles in another
session.
Session 0:
   h=:1!:21<'xxx'
   h
34035648

Session 1:
   load 'C:\j602\system\packages\files\bigfiles.ijs'
   fdir 'xxx'
+---+-------------------+-+---+------+
|xxx|2006 12 15 10 41 25|3|rw-|-----a|
+---+-------------------+-+---+------+
   bfsize_jbf_ 'xxx'
+--+---------------------------------------------------------------------------------+
|32|The process cannot access the file because it is being used by another
process.  |
+--+---------------------------------------------------------------------------------+

Notice that somehow fdir is able to get the size of the file but bfsize_jbf_
is not.

Back to session 0:
   1!:22 h
1

And now in session 1:
   bfsize_jbf_ 'xxx'
0 3

Once the file is closed in session 0 the file is accessible to bigfiles.

How is fdir able to get to the file size? Is it reading the directory
directly avoiding having to open the file? Or what?


On Sun, Nov 30, 2008 at 7:43 PM, David Mitchell <[EMAIL PROTECTED]>wrote:

Don Guinn wrote:

I ran into problems when using fdir (1!:0) when the files were larger than
2
gig. The size of the file is wrong as is documented. I addressed this by
using bigfiles and it worked well until I tried to get the size of a file
that was open by another application. Then bfsize_jbf_ fails. What
confuses
me is that somehow 1!:0 can retrieve the size of the file (though
incorrect)
even though it is open to another application. As best as I can tell all
file tools provided by Microsoft require file handles implying that the
file
has been opened.
So how does 1!:0 get the file size for files open to other applications?
It
would be nice if bigfiles could use the same technique.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm


This worked for me:

FindFirstFile=: 'kernel32 FindFirstFileA i *c *'&cd
FindClose=: 'kernel32 FindClose i i'&cd


findd=:318$'a'
ffsize=:28+i.8
INVALID_HANDLE_VALUE=: _1

NB. =========================================================
NB.*fffsize v get file size using windows API
NB. form: fffsize file_path_name
fffsize=: 3 : 0
'fh ft fv'=. FindFirstFile y;findd
if. INVALID_HANDLE_VALUE~:fh do.
 r=.b32to64 ctoi"1]2 4$ffsize{fv
 FindClose fh
else.
 r=.''
end.
r
)

--
David Mitchell

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to