Why does this crash every time???
Posted: Fri Nov 14, 2003 12:43 am
Yep, me again with another stupid question. Why does this crash every time the "renamefiles" procedure is called?
It seems that as soon as the renamefiles proc is called and it hits the ExamineDirectory command, it craps out. I've run it with all the statements in the proc commented out except ExamineDirectory, and that's what seems to crash it...is there a way to "close" a directory, before using "ExamineDirectory()" again? Is that what's doing it? I've also tried changing the directory ID to "2", with the same results....
Thanks, as always!
Bryan
Code: Select all
Enumeration
#Window_0
EndEnumeration
Enumeration
#oldextbox
#newextbox
#renamebutton
#browsebutton
#Gadget_5
#Gadget_6
#listbox
EndEnumeration
Procedure Open_Window_0()
If OpenWindow(#Window_0, 259, 121, 652, 359, #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar , "batchRenamer")
If CreateGadgetList(WindowID())
StringGadget(#oldextbox, 30, 330, 110, 20, "")
StringGadget(#newextbox, 260, 330, 120, 20, "")
ButtonGadget(#renamebutton, 150, 330, 100, 20, "Rename File!")
ButtonGadget(#browsebutton, 20, 10, 140, 30, "Browse For Folder")
TextGadget(#Gadget_5, 30, 310, 110, 20, "Old Extension:")
TextGadget(#Gadget_6, 260, 310, 120, 20, "New Extension:")
ListViewGadget(#listbox, 20, 50, 620, 260)
EndIf
EndIf
EndProcedure
Procedure listfiles(path$)
result = ExamineDirectory(1, path$, "*.*")
If result = 0: MessageRequester("Error!", "Can't open directory!"):ProcedureReturn:EndIf
ClearGadgetItemList(#listbox)
Repeat
result = NextDirectoryEntry()
If result = 1
AddGadgetItem(#listbox, -1, DirectoryEntryName())
ElseIf result = 0
ProcedureReturn
EndIf
ForEver
EndProcedure
Procedure renamefiles(oldext$, newext$)
ExamineDirectory(1, path$, "*.*")
ClearGadgetItemList(#listbox)
Repeat
result = NextDirectoryEntry()
If result = 1
filename$ = DirectoryEntryName()
oldfilename$ = filename$
If Right(filename$, 3) = oldext$
filename$ = Left(filename$, Len(filename$)-3) + newext$
RenameFile(path$ + oldfilename$, path$ + filename$)
EndIf
AddGadgetItem(#listbox, -1, filename$)
ElseIf result = 0
ProcedureReturn
EndIf
ForEver
EndProcedure
Global path$
Open_Window_0()
Repeat
Event = WaitWindowEvent()
If Event = #PB_EventGadget
GadgetID = EventGadgetID()
If GadgetID = #renamebutton
If GetGadgetText(#oldextbox) = "" Or GetGadgetText(#newextbox) = ""
MessageRequester("Error!", "No extensions specified!")
ElseIf path$ = ""
MessageRequester("Error!", "No path specified!")
Else
oldext$ = GetGadgetText(#oldextbox)
newext$ = GetGadgetText(#newextbox)
renamefiles(oldext$, newext$)
EndIf
ElseIf GadgetID = #browsebutton
path$ = PathRequester("Choose a folder:", "")
listfiles(path$)
EndIf
EndIf
Until Event = #PB_EventCloseWindow
End
Thanks, as always!
Bryan