files on external drives
Moderator: Rathinagiri
Re: files on external drives
Hi Templar
Sorry to hijack your thread for my problem.
Sorry to hijack your thread for my problem.
Re: files on external drives
Nope, not corrupt, and I've tried it with several files....serge_girard wrote: ↑Sun Mar 29, 2020 4:33 pm Templar,
File is maybe corrupt?
Try another file.
Serge
Re: files on external drives
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.
Re: files on external drives
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
Re: files on external drives
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
Re: files on external drives
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
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
- AUGE_OHR
- Posts: 2065
- Joined: Sun Aug 25, 2019 3:12 pm
- DBs Used: DBF, PostgreSQL, MySQL, SQLite
- Location: Hamburg, Germany
Re: files on external drives
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
set next Parameter to 0 ( zero)
read more about this here http://technet.microsoft.com/en-us/libr ... 10%29.aspx
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
Code: Select all
DirectoryCacheLifetime
FileNotFoundCacheLifetime
FileInfoCacheLifetime
have fun
Jimmy
Jimmy
Re: files on external drives
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.
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.
- serge_girard
- Posts: 3178
- Joined: Sun Nov 25, 2012 2:44 pm
- DBs Used: 1 MySQL - MariaDB
2 DBF - Location: Belgium
- Contact:
Re: files on external drives
I tried this:
And it gives 'All OK' !
Serge
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
Serge
There's nothing you can do that can't be done...
Re: files on external drives
Try this code: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
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