files on external drives

Topic Specific Tutorials and Tips.

Moderator: Rathinagiri

RPC
Posts: 285
Joined: Fri Feb 10, 2017 4:12 am
DBs Used: DBF

Re: files on external drives

Post by RPC »

Hi Templar
Sorry to hijack your thread for my problem.
Templar
Posts: 51
Joined: Sun Apr 01, 2018 5:37 pm
DBs Used: DBF

Re: files on external drives

Post by Templar »

serge_girard wrote: Sun Mar 29, 2020 4:33 pm Templar,

File is maybe corrupt?
Try another file.

Serge
Nope, not corrupt, and I've tried it with several files....
Templar
Posts: 51
Joined: Sun Apr 01, 2018 5:37 pm
DBs Used: DBF

Re: files on external drives

Post by Templar »

One further clue: trying to re-copy the file produces a "Sharing Violation" error, so it seems that although the file has been closed, something about the copying has classed it as still being open.
Templar
Posts: 51
Joined: Sun Apr 01, 2018 5:37 pm
DBs Used: DBF

Re: files on external drives

Post by Templar »

mol wrote: Sun Mar 29, 2020 5:46 pm Try to prepare working sample producing error.
Some of us have a lot of time now...
Okay, here goes:
1 cFILE1:= "C:\BOOKS\AUTHORS.dbf"
2 cFile2:= "E:\BOOKS\AUTHORS.dbf"
3 COPY FILE &cFile1 TO &cFile2
4 IF FILE("&cFile2")
5 USE &cFile2
6 GO TOP
7 ELSE
8 ? "No such file" ; INKEY(0) ; RETURN
9 ENDIF

This will produce a "Workarea not in use" message at line 6
I've spent about 12 hours on this so far, tryting to see what the problem is!
Any suggestions very gratefully received.
Templar
edk
Posts: 911
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: files on external drives

Post by edk »

From what you describe, the question arises whether this file is open in another application or is already open file with the same name in another work area?

Code: Select all

For i=1 To 999
   If Alias( i ) = "AUTHORS"
       Msginfo ( "Alias 'Authors' is already open in " + str (i) + " work area.")
     Endif
Next i
Templar
Posts: 51
Joined: Sun Apr 01, 2018 5:37 pm
DBs Used: DBF

Re: files on external drives

Post by Templar »

Yes but it is not open! Let me revise the sample:
1 CLOSE ALL
2 cFILE1:= "C:\BOOKS\AUTHORS.dbf"
3 cFile2:= "E:\BOOKS\AUTHORS.dbf"
4 COPY FILE &cFile1 TO &cFile2
5 IF FILE("&cFile2")
6 USE &cFile2
7 GO TOP
8 ELSE
9 ? "No such file" ; INKEY(0) ; RETURN
10 ENDIF

This will produce a runtime error, "Workarea not in use" at line 7

Templar
User avatar
AUGE_OHR
Posts: 2062
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: files on external drives

Post by AUGE_OHR »

hi,

please us Code TAGS

---

as cFile2 was just "create" it is IMHO in local SMB2 CACHE ... just Filename exist but Size still 0
so put some SLEEP(x) and "test" with NETERR(), in a Loop, if you can open DBF

---

SMB2 CACHE can be disable under

Code: Select all

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Lanmanworkstation\Parameters
set next Parameter to 0 ( zero)

Code: Select all

DirectoryCacheLifetime
FileNotFoundCacheLifetime
FileInfoCacheLifetime
read more about this here http://technet.microsoft.com/en-us/libr ... 10%29.aspx
have fun
Jimmy
RPC
Posts: 285
Joined: Fri Feb 10, 2017 4:12 am
DBs Used: DBF

Re: files on external drives

Post by RPC »

Hi Templar
Have you tried using ALIAS clause, and what about NEW clause which will open DBF file in new work area.
I could not repeat your error as your code is working perfect as you have provided.
User avatar
serge_girard
Posts: 3166
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: files on external drives

Post by serge_girard »

I tried this:

Code: Select all

CLOSE ALL
cFILE1 := "C:\TEST\F0001.DBF"
cFile2 := "C:\TEST\F0001C.DBF"
cFile3 := "F:\TEST\F0001C.DBF"
cFile4 := "G:\TEST\F0001C.DBF"
cFile5 := "P:\TEST\F0001C.DBF"
cFile6 := "Q:\TEST\F0001C.DBF"
cFile7 := "Y:\TEST\F0001C.DBF"
cFile8 := "z:\TEST\F0001C.DBF"

COPY FILE &cFile1 TO &cFile2
COPY FILE &cFile1 TO &cFile3
COPY FILE &cFile1 TO &cFile4
COPY FILE &cFile1 TO &cFile5
COPY FILE &cFile1 TO &cFile6
COPY FILE &cFile1 TO &cFile7
COPY FILE &cFile1 TO &cFile8

 
IF FILE("&cFile2")
   USE &cFile2 ALIAS C2 NEW 
   GO TOP

   USE &cFile3 ALIAS C3 NEW 
   GO TOP

   USE &cFile4 ALIAS C4 NEW 
   GO TOP

   USE &cFile5 ALIAS C5 NEW 
   GO TOP

   USE &cFile6 ALIAS C6 NEW 
   GO TOP

   USE &cFile7 ALIAS C7 NEW 
   GO TOP

   USE &cFile8 ALIAS C8 NEW 
   GO TOP
   msginfo( "ALL ok" )

ELSE
   msginfo( "No such file" )
ENDIF
And it gives 'All OK' !

Serge
There's nothing you can do that can't be done...
edk
Posts: 911
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: files on external drives

Post by edk »

Templar wrote: Tue Mar 31, 2020 9:40 am Yes but it is not open! Let me revise the sample:
1 CLOSE ALL
2 cFILE1:= "C:\BOOKS\AUTHORS.dbf"
3 cFile2:= "E:\BOOKS\AUTHORS.dbf"
4 COPY FILE &cFile1 TO &cFile2
5 IF FILE("&cFile2")
6 USE &cFile2
7 GO TOP
8 ELSE
9 ? "No such file" ; INKEY(0) ; RETURN
10 ENDIF

This will produce a runtime error, "Workarea not in use" at line 7

Templar
Try this code:

Code: Select all

#include "HMG.CH"

FUNCTION main()

Local cFile1:= "C:\BOOKS\AUTHORS.dbf"
Local cFile2:= "E:\BOOKS\AUTHORS.dbf"
Local nSuccess

CLOSE DATA
IF !File ( cFile1 )
	MsgStop ( "File " + cFile1 + " doesn't exist", "Error" )
	RETURN
ENDIF

IF !hb_DirExists ( hb_FNameDir ( cFile2 ) )
	//Try to create folders structure
	IF !hb_DirBuild(hb_FNameDir ( cFile2 ))
		MsgStop ( "Error while creating folder " + hb_FNameDir ( cFile2 ), "Error" )
		RETURN
	ENDIF
ENDIF

IF ( nSuccess := hb_FCopy (cFile1 , cFile2) ) <> 0
	MsgStop ( "Error #" + hb_ValToStr( nSuccess) + " while copying from " + cFile1 + " to " + cFile2, "Error" )
	RETURN
ENDIF

IF !File ( cFile2 )
	MsgStop ( "File " + cFile2 + " doesn't exist.", "Error" )
	RETURN
ENDIF

IF hb_FSize( cFile1, .F. ) <> hb_FSize( cFile2, .F. )
	MsgStop ( "The sizes of both files do not match", "Error" )
	RETURN
ENDIF

USE &cFile2

DO WHILE NETERR()
	IF !MsgRetryCancel("Error opening file. Try again?", "USE error") 
		MsgStop ("Canceled")
		EXIT
	ENDIF
	USE &cFile2
ENDDO

IF Empty ( Alias() )
	MsgStop ( 'The "USE" command failed.', "Failed")
	RETURN
ENDIF

GO TOP

MsgInfo ("Successfully")

CLOSE DATA
RETURN
Post Reply