Problems with CopyFile, DeleteFile and ExecFile

Blitz3D Forums/Blitz3D Beginners Area/Problems with CopyFile, DeleteFile and ExecFile

ThE_oMiKrOn_CaT(Posted 2003) [#1]
Hello, im trying to run this simple program when i drag a file onto the exec to copy it to a certain directory but it doesnt seem to work:

file$=CommandLine$()
CopyFile(file$,"e:\mp3\")

I also get no effect when using Deletefile() or Execfile()
i dont understand y it isnt working, does any1 know?

thanx

Oli


Perturbatio(Posted 2003) [#2]
the filename will contain the full path of the file passed via commandline, you will need to extract the filename (everything after the last backslash) and then append it to the second parameter of CopyFile

This works because I have specified the filename to copy to:
file$=CommandLine$() 
CopyFile(file$,"c:\temp\test.txt") 
Print file$
WaitKey()
End



Perturbatio(Posted 2003) [#3]
Here's a simple example:

file$=CommandLine$() 
CopyFile(file$,"c:\temp\"+ExtractFileName$(file$)) 
Print file$

Print ExtractFileName$(file$)

WaitKey()
End


;FUNCTION ExtractFileName
;Accepts a filepath and returns the filename

Function ExtractFileName$(sFilePath$)
;LOCAL VARS
Local iStartPos% = 0
Local iSearchPos% = 0
Local iFileNameLength = 0
Local sFileName$ = ""
	
;BEGIN FUNCTION CODE
iFileNameLength = Len(sFilePath$)
iSearchPos% = iFileNameLength
 
While (iStartPos% < 1) And (iSearchPos%>1)

	iStartPos% = Instr(sFilePath$, "\", iSearchPos%)
	iSearchPos% = iSearchPos% - 1
	
Wend

If iStartPos = 0 Then ;if the filepath contains no backslashes
	sFileName$ = sFilePath$
Else
	sFileName$ = Right$(sFilePath$, iFileNameLength% - iStartPos%)
EndIf


Return sFileName$

End Function



ThE_oMiKrOn_CaT(Posted 2003) [#4]
ah ok, that was stupid of me lol! well i have copyfile and execfile working but deletefile still doesnt seem to work...


Perturbatio(Posted 2003) [#5]
You want to delete the file that is dragged onto your app?

I had a bit of trouble with it, it would appear to be related to long filenames

you need to remove the quotes from either side of the filename (don't ask me why)

this works:
file$=CommandLine$() 
;REMOVE THE QUOTES
file$= Left(file$,Len(file$)-1)
file$ = Right(file$, Len(file$)-1)

If FileType(file$) = 1 Then DeleteFile ""+file$
If FileType(file$) = 1 Then Print "not deleted" Else Print "deleted"
Print FileType(file$)
Print file$

WaitKey()
End



ThE_oMiKrOn_CaT(Posted 2003) [#6]
thanx perturbatio, i guessed it would be something weird like that!

ill look into it, thanx for the code!

Oli


Perturbatio(Posted 2003) [#7]
np :)

You need to check for the quotes first, since a file located on the C:\ root without any spaces in it will not be quoted for instance.