Page 1 of 1

deleting a file

Posted: Sun Nov 14, 2004 12:37 am
by lucid
I am trying to delete all files in a specific directory.

I placed a debug code to tell me if the delte process fails, and for some reason... I can not delete any of the files :(

Here is my code (only the applicable part):

Code: Select all


             #HistoryDir.s  = "history\" ;history directory
             #HistoryExt.s  = ".hx"      ;history extension

              ExamineDirectory(#PB_Any, #HistoryDir, "*"+#HistoryExt)
              Repeat
                FileType = NextDirectoryEntry()
                If FileType = 1
                  FileName$ = DirectoryEntryName()
                    Debug(FileName$)
                    If DeleteFile(FileName$)=0:Debug "cant delete":EndIf 
                EndIf 
              Until FileType = 0  


the debug Filename$ is returning the proper file name in the directory. But The debug "cant delete" comes up for every file name. In other words, no files in this history directory are being deleted and I want to delete all of them if the user confirms that he/she wants to delete their "history"



Thanks in advance

Posted: Sun Nov 14, 2004 1:07 am
by Beach
You need to add the path for DeleteFile()...

Posted: Sun Nov 14, 2004 1:22 am
by Beach
Using your code:

Code: Select all

#HistoryDir.s  = "history\" ;history directory
#HistoryExt.s  = ".hx"      ;history extension

ExamineDirectory(#PB_Any, #HistoryDir, "*"+#HistoryExt)
Repeat
  FileType = NextDirectoryEntry()
  If FileType = 1
    FileName$ = DirectoryEntryName()
    Debug(FileName$)
    If DeleteFile(#HistoryDir + FileName$)=0:Debug "cant delete":EndIf
  EndIf
Until FileType = 0

Posted: Sun Nov 14, 2004 1:29 am
by lucid
stupid me.

that was it, thanks.