1.

Solve : Deleting Files Using Vbs?

Answer»

I am kind of new to visual basic script and I am wondering how I can delete files and folders using it? Is there a delete command?i know there is the Kill command, but thats for processes... gime a sek i have tons of old code on my pc...

lol this is from the most intricate program ive ever made... so far... but im working on a game so its going to lose its spot

To create a file, txt in this instance
Code: [Select]Dim namefile As String
namefile = Text1
If Text1.Text = "" Then
MsgBox "fill in a username"
Else
If Text2.Text = "" Then
MsgBox " fill in a password"
Else
Open App.Path & "/Accounts/Users/" + namefile + ".txt" For Output As #1
Print #1, Text1.Text
Print #1, Text2.Text
Close #1
End If
End If


nope i was wrong... kill does work for files
Code: [Select]Kill App.Path & "\Accounts\Users\" + "openfile.txt"
MsgBox "Deleted"
Explanation:

Kill-- MEANS delete
app.path --- means open the directory the program is located
& "\accounts\users\" --- means to open these folders ON TOP of the application path such as C:/game/ , but instad it would open c:/game/accounts/users
+ --- the file you wish to delete, but in COMPUTER it means AND
"openfile.txt" --- SIMPLY naming the file were getting rid of


I HAVE NOT TRIED THE FOLLOWING SO DONT SAY "YOU WERE WRONG"

i think that if you REMOVE everything after the + sign including the + sign it will delete the folder... but im not positive...You can use methods of the file system object for both files and folders:

Files:
Code: [Select]Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFile filespec, True

Folders:
Code: [Select]Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFolder folderspec, True

Replace filespec and folderspec as needed. The True parameter will force the delete on read-only files/folders.



PS. VBScript does not have a kill instruction.



Discussion

No Comment Found