Declare.l InstrRev(xChar1.s)


Procedure ProcessFile(xChar1.s)
  If DeleteFile(xChar1) = 0
    PrintN ("Cannot delete file: " + xChar1)
    EndIf
  EndProcedure


OpenConsole()
PrintN("Kill 1.00 - Deletes the specified file(s)")
PrintN("Freeware / Open source, 2004 by Jan Vorel as helper application for ctConvF")
PrintN("Written in / compiled with PureBasic")
PrintN("")

xLong1.l
xChar2.s
xChar1.s = ProgramParameter()
If xChar1 = ""
  PrintN("Usage: Kill <File(s)> [<File(s)> [<File(s)> ...]]")
  Else
  Repeat
    If xChar1 = ""
      Break
      Else
      xLong1 = InstrRev(xChar1)
      If xLong1 = 0
        xChar2 = ""
        Else
        xChar2 = Left(xChar1, xLong1 - 1)
        xChar1 = Mid(xChar1, xLong1 + 1, Len(xChar1) - xLong1)
        EndIf
      If ExamineDirectory(#PB_Any, xChar2, xChar1) = 0
        Else
        Repeat
          xLong1 = NextDirectoryEntry()
          If xLong1 = 1
            If xChar2 = ""
              xChar1 = DirectoryEntryName()
              Else
              xChar1 = xChar2 + "\" + DirectoryEntryName()
              EndIf
            If FileSize(xChar1) >= 0
              ProcessFile (xChar1)
              EndIf
            EndIf
          Until (xLong1 = 0)
        EndIf
      EndIf
    xChar1 = ProgramParameter()
    ForEver
  EndIf
;Repeat
;ForEver
End


Procedure.l InstrRev(xChar1.s)
  xLong1.l
  xLong2.l

  While 1
    xLong1 = FindString(xChar1, "\", xLong2 + 1)
    If xLong1 = 0 
      Break
      Else
      xLong2 = xLong1
      EndIf
    Wend
  ProcedureReturn = xLong2
  EndProcedure

; ExecutableFormat=Console
; Executable=D:\VB6\ctConvF\helpers\kill.exe
; EOF