QB64.org Forum
		Active Forums => QB64 Discussion => Topic started by: xra7en on April 02, 2021, 12:43:30 pm
		
			
			- 
				Hi
stuck home with a positive test arg! so tinkering with some old app I have laying around.
while I don't mind using the shell command, I try to avoid it when I can.
I noticed that there is not a copy command.
so trying the kill (https://www.qb64.org/wiki/KILL)/name  (http://www.qb64.org/wiki/NAME)commands
Problem: KILL produces a file not closed error - when it clearly is and NAME produces an error, most likely because the KILL command error has not been fixed. So before I tackle the NAME error, can someone check out what is wrong with the KILL command?
        FF = FreeFile
        If _FileExists("temp.tmp") Then Kill "temp.tmp"
        Open DB_FILE For Input As #FF:
        HH = FreeFile
        Open "temp.tmp" For Append As #HH
        While Not EOF(FF)
                Line Input #FF, aline
                If RECNUM = cnt Then
                        Print #HH, INFO
                Else
                        Print #HH, aline
                End If
               cnt = cnt + 1
        Wend
        Close #HH
        Close #FF
        Kill DB_FILE '<-- program fails here with file not closed
        Name "temp.tmp" As DB_FILE
			 
			
			- 
				SUB Copy (file1$, file2$)
    OPEN file1$ FOR BINARY AS #1
    l = LOF(1)
    s$ = SPACE$(l)
    GET #1, 1, s$
    CLOSE #1
    OPEN file2$ FOR OUTPUT AS #1: CLOSE #1
    OPEN file2$ FOR BINARY AS #1
    PUT #1, 1, s$
    CLOSE #1
END SUB
			 
			
			- 
				aw man too fast for me. LOL
I actually found the issue as I was re-reading my post... as an experiment I put a 
CLOSE #1, CLOSE #2 at the top of this sub
and it worked. Which leads to my next question. When I do a 
OPEN  command, I immediately follow up with a close command. Is there a way to check my work to find out where (if any) my straggler close commands are?
EDIT:
THANK you for the copy sub!! That should be added to a next revision.. :-)
			 
			
			- 
				Glad you got this fixed. Hope you feel better soon!
			
 
			
			- 
				
Glad you got this fixed. Hope you feel better soon!
thanks!!
Im used to working all day so feels weird just sittin' around LOL
However, only got it partially fixed.
			 
			
			- 
				CLOSE without any argument will close all open files.
			
 
			
			- 
				
CLOSE without any argument will close all open files.
thanks! that is very helpful
So with my current conundrum, how would I seek out and destroy any stragglers :-)
			 
			
			- 
				
thanks! that is very helpful
So with my current conundrum, how would I seek out and destroy any stragglers :-)
What is straggling? certainly not open files not closed yet because you just learned, I think lol, that CLOSE without argument closes them all.
Sometimes when I do file work I have to ChDir and change back to get the system to update it's file listing for the folder that I am working in like renaming files, moving, removing... specially working from QB64.
			 
			
			- 
				
What is straggling? certainly not open files not closed yet because you just learned, I think lol, that CLOSE without argument closes them all.
Sometimes when I do file work I have to ChDir and change back to get the system to update it's file listing for the folder that I am working in like renaming files, moving, removing... specially working from QB64.
yes the magic CLOSE works, but for me that is a little sloppy if i have an if/then/else floating that left one of them OPEN. Trying to keep it clean. You can check the source - I put it in programs - its a password manager - I am betting there is a case/select or if/then/else messing up the flow of closes :-)