deleting a file

Just starting out? Need help? Post your questions and find answers here.
lucid
New User
New User
Posts: 5
Joined: Wed Nov 03, 2004 11:40 pm

deleting a file

Post 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
Beach
Enthusiast
Enthusiast
Posts: 677
Joined: Mon Feb 02, 2004 3:16 am
Location: Beyond the sun...

Post by Beach »

You need to add the path for DeleteFile()...
-Beach
Beach
Enthusiast
Enthusiast
Posts: 677
Joined: Mon Feb 02, 2004 3:16 am
Location: Beyond the sun...

Post 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
-Beach
lucid
New User
New User
Posts: 5
Joined: Wed Nov 03, 2004 11:40 pm

Post by lucid »

stupid me.

that was it, thanks.
Post Reply