|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (8 bit)
|
Visual Basic help
Could anyone help me out with deleting files in visual basic? Iv scavenged the internet for ages reading about the Kill and Delete functions but it all seems unclear and explained in unnecesary ways, and often the code doesnt work for some reason. All i want to be able to do is to delete files in a folder.
So for example, delete all the files in "folder X", and if there are no files, then it does nothing. This at a glance did not sound hard at all..but bare in mind im still at college. havnt been doing computing for a year yet. ![]() Thanks Rowan *Edit* Sorry i forgot to mention the main bit, need help doing it for Hidden files. i tried this: Private Sub Command1_Click() Dim DeleteFolder As String DeleteFolder = "C:\Users\admin\Desktop\DeleteFolder\*.*" SetAttr DeleteFolder, vbNormal Kill DeleteFolder End Sub but "SetAttr DeleteFolder, vbNormal" is a bad file name or number apparantly. Iv tried so many variations, doing it all different ways i could think of. thanks Last edited by RowanSpry; 05-08-2008 at 03:52 PM. |
|
|
|
|
|
#2 |
|
Member (8 bit)
|
And also how to do it for multiple files.
|
|
|
|
|
|
#3 |
|
Member (9 bit)
Join Date: May 2007
Location: USA, New Jersey
Posts: 447
|
Your problem is the line above because wildcards "*" do not work with the SetAttr command.
I modified your example to do as you wish. Basically you need to locate the hidden file and change it's attribute, then locate each subsequent file using DIR() and change each file's attribute. ---pete--- Code:
Sub DeleteFiles()
Dim DeleteFiles As String
Dim Folder As String
Dim a$
DeleteFiles = "C:\Temp\*.*"
Folder = "C:\Temp\"
'Locate first hidden file in target folder
'then make it a normal unhidden file.
a$ = Dir(Folder, vbHidden)
SetAttr Folder & a$, vbNormal
'Proceed to check each file in the target folder
'and change each to a normal unhidden file.
Do
On Error GoTo Abort:
SetAttr Folder & Dir(), vbNormal
Loop
Abort:
Kill DeleteFiles
End Sub
|
|
|
|
|
|
#4 |
|
Member (8 bit)
|
Cheeeeeeeeeeers
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Visual Basic Code | cuzzzzzz | Web Design / Development | 4 | 02-20-2007 07:54 PM |
| Visual Basic compatability question | waiting | Software Discussion & Support | 3 | 11-07-2004 08:45 PM |
| Visual Basic | Craig100 | Web Design / Development | 1 | 08-26-2004 01:05 PM |
| HOW do i make a program i written with visual basic 6 run with out visual basic 6 | jaxson | Web Design / Development | 6 | 07-08-2003 09:39 AM |
| Visual Studio .NET install | MikeeX | Web Design / Development | 19 | 09-27-2002 06:16 PM |