TIPCORNER - DELETING AND RENAMING DISK FILES
Novice level
by Alyce Watson, 2002

Home

Liberty BASIC News
Safe Registry and Ini File Alternative
Deleting and Renaming Disk Files
Segments and Flushing
Flat Toolbar with Toolips
Translating 32-bit VB API Calls
Event-Driven Programming Concepts
Spotlight on the Community!
ODBC in Liberty BASIC
Hex Viewer
Listing Files Recursively
Registering Hot Keys
Preventing more than 1 instance
Multi-Coloured Text Input Boxes
Images on Buttons and Statictext
Two Demos by David Conner

DELETING FILES
Liberty BASIC allows us to delete files with the KILL command. Note that they will not be placed into the recycle bin. They will be permanently deleted.

syntax:

KILL filename$

In the above example, filename$ must be the name of an existing file on disk. If you try to KILL a file that doesn't exist, the program will halt with an error. If the filename$ doesn't contain a path, it is assumed to be in the same folder as the Liberty BASIC program. This folder is contained in the variable DefaultDir$. The following little demo creates a text file, then kills it. The file is created in the DefaultDir$ because no path information is included in the filename$ parameter.

open "hello.txt" for output as #f
    print #f, "hi"
    close #f
    kill "hello.txt"

Here, we let the user choose a file to delete:

filedialog "File to Delete","*.*",filename$
if filename$="" then 
    print "Cancelled!"
else 
    kill filename$
    print filename$;" deleted!"
end if


RENAMING FILES (MOVING FILES)
We can rename a file with the NAME statement. Files can be moved to other folders using the NAME statement. To rename the file, "readme.txt" to "message.txt":

NAME "readme.txt" as "message.txt"

To move the file, "c:\info\readme.txt" to c:\myfiles\readme.txt":

NAME "c:\info\readme.txt" as "c:\myfiles\readme.txt"

Just as with the KILL command, an attempt to NAME a file that doesn't exist will cause the program to halt with an error. Also, as with the KILL command, if no path is given for the filename$, it is assumed to be in the same directory as the program, which is the DefaultDir$

Here is a demo that allows a user to rename a file.

filedialog "File to rename","*.txt",oldfile$
if oldfile$="" then end

filedialog "New name","*.txt",newfile$
if newfile$="" then end

name oldfile$ as newfile$

  

Home

Liberty BASIC News
Safe Registry and Ini File Alternative
Deleting and Renaming Disk Files
Segments and Flushing
Flat Toolbar with Toolips
Translating 32-bit VB API Calls
Event-Driven Programming Concepts
Spotlight on the Community!
ODBC in Liberty BASIC
Hex Viewer
Listing Files Recursively
Registering Hot Keys
Preventing more than 1 instance
Multi-Coloured Text Input Boxes
Images on Buttons and Statictext
Two Demos by David Conner