Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 05-08-2008, 03:16 PM   #1
Member (8 bit)
 
Join Date: Oct 2006
Location: North Devon, England
Posts: 148
Send a message via MSN to RowanSpry
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.
RowanSpry is offline   Reply With Quote
Old 05-09-2008, 08:28 AM   #2
Member (8 bit)
 
Join Date: Oct 2006
Location: North Devon, England
Posts: 148
Send a message via MSN to RowanSpry
And also how to do it for multiple files.
RowanSpry is offline   Reply With Quote
Old 05-09-2008, 09:40 PM   #3
Member (9 bit)
 
Join Date: May 2007
Location: USA, New Jersey
Posts: 447
Quote:
Originally Posted by RowanSpry View Post
SetAttr DeleteFolder, vbNormal
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
Petef56 is offline   Reply With Quote
Old 05-13-2008, 11:59 AM   #4
Member (8 bit)
 
Join Date: Oct 2006
Location: North Devon, England
Posts: 148
Send a message via MSN to RowanSpry
Cheeeeeeeeeeers
RowanSpry is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -5. The time now is 07:36 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2