File Error
BlitzPlus Forums/BlitzPlus Programming/File Error
| ||
| Hello. I wrote this code and the program keeps crashing at the indicated line. The DOES exist but for some reason I'm missing, the compiler gives me the error 'File Does Not Exist' when it clearly does physically reside on the drive. What Am I doing wrong? Thans for your help
AppTitle "PTw":Graphics 600,400,24,2:.AGA CN=0:DU=0:RS=0:GF$=Upper$(Input("N: ")):If GF$="" Then HALT(2):
LO$=CurrentDir$():FIN$=LO$+GF$+"_RAW.TXT"::;Print FIN$:HALT(2)
Print "FIN$: "+FIN$:FIN2$=LO$+"TESTFILE.TXT":Print "FIN2$: "+FIN2$:For II= Len(FIN$) To 1 Step -1 ;last \
If Mid$(FIN$,II,1)<>"\"
RS=RS+1
ElseIf Mid$(FIN$,II,1)="\"
Exit
EndIf ;
Next: NTM$=Mid$(FIN$,Len(FIN$)-RS+1):NTM$=Left$(NTM$,Instr(NTM$,"_")-1)+Mid$(NTM$,Instr(NTM$,"."))
NTM$=Left$(FIN$,Len(FIN$)-RS)+NTM$:Print "NTM$: "+NTM$:Print FileSize(NTM$):;HALT(1)
TFN=OpenFile(NTM$) ;MkF
If TFN=0 And FileSize(NTM$)=0
TFN=WriteFile(NTM$):If FileSize(NTM$)>0 CloseFile (TFN) ;MAKE
TFN=OpenFile(NTM$):Print NTM$+" CREATED":
EndIf
;====
; TFN=OpenFile(NTM$) ;
; If TFN=0 And FileSize(NTM$)=0 ;After I changed this line to 'If filesize(NTM$)=0 And TFN=0, it crashed --V
; TFN=WriteFile(NTM$):If FileSize(NTM$)>0 CloseFile (TFN) ;< -------- It's stopping here, however ^
; TFN=OpenFile(NTM$):Print "YES":
; EndIf
CR=0;
While Not Eof(TFN) ;Red
TS$=ReadLine(TFN):CR=CR+1
If TS$=TH$ ;E
FFL=1:DU=DU+1
EndIf
Wend
If FFL=0
WriteLine(TFN,TH$):CloseFile(TFN):AR=AR+1 ; - -- - - - - - ------------------------------ Down here
EndIf
FFL=0
;====
EndIf
.COUNT Wend
.INF Print DU+" F "+(CN-DU)+" S "+AR+" W":CloseFile(OFN):If FileSize(NTM$)>0 Then CloseFile(TFN):
Goto AGA
Function HALT(P=0)
If P=2 Then End ElseIf P=1 Then WaitKey:Return ElseIf P=0 Then WaitKey:End
End End Function
|
| ||
| Sorry but I cannot make head nor tail of that code. It's probably the most unreadable example of code I've ever seen. But for what it's worth, you should probably be using FileType() somewhere to check that the files does exist, before trying to do [whatever it is you're attempting to do] with it. |
| ||
| FileSize will NEVER be > 0 for WriteFile() WriteFile will always create new, empty files, overwriting if required. Instead of all this rubbish: You only need: It would be MUCH easier if you spaced your code out more with some formatting and whitespace, not using too many : and gave variables and handles more understandable names. Don't reuse vars and handles withiout being absolutely sure you've finished with them in scope. Don't open/close streams that are already open!!! |