Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Confused newbie


Reply
 
Thread Tools Display Modes
  #1  
Old 08-15-2001, 12:09 PM
hghfdhf
Guest
 
Posts: n/a
Question Confused newbie


Ok here is my problem, I want my program to delete all the files in the history folder so I used KILL "C:\windows\history\*.*" but it always give me an error. I don't know what to do. Thanks for your help in advance.

Reply With Quote
  #2  
Old 08-15-2001, 12:23 PM
KesleyK's Avatar
KesleyK KesleyK is offline
Senior Contributor

Retired Moderator
* Expert *
 
Join Date: Jun 2001
Location: Idaho, missing Dallas
Posts: 965
Default Re: Confused newbie

Try enumerating through the files, deleting one at a time. On an error, check the attributes and modify if necessary.


"Recently reported by the Assoc. of Incomplete Research, 7 out of 10 people." -- K. Nealon, SNL
__________________
We shall persevere.
Reply With Quote
  #3  
Old 08-15-2001, 12:54 PM
hghfdhf
Guest
 
Posts: n/a
Question Re: Confused newbie

How do I do that?

Reply With Quote
  #4  
Old 08-15-2001, 01:35 PM
cyclonebri cyclonebri is offline
Centurion
 
Join Date: Jun 2001
Location: Ames, Iowa, USA
Posts: 164
Default Re: Confused newbie

Hey, another command you might try is this:

Add the reference "Microsoft Scripting Runtime" to your project and then in your command sub() do this:

'create new FileSystemObject
dim fsoMain as new FileSystemObject
dim strFileName as string

strFileName = "C:\Windows\history\*.*
do while fsoMain.fileexists(strFileName) = true

'Delete files
fsoMain.DeleteFile strFileName
if err then
debug.print err.description
end if

loop
'*** end of code

hope this helps. Also, check to make sure that you have proper permissions and that the path you are using is correct as these can be big problems as well. Good Luck!

also, if you wanted you could make a boolean and do this:

dim fsoMain as newFileSystemObject
dim boolDeleted as boolean
dim strFileName as string

strFileName = "C:\..."

do while fsoMain.FileExists(strFileName) = true

Deleted = fsoMain.DeleteFile(strFileName)
if Deleted = true then
debug.print "Deleted File"
else
debug.print err.description
endif

Loop

'***endofcode

Good Luck

**************OOOPS, my bad***************
since you don't know the name of the file and are using the wildcards, take out the lines for fileexists and the loop and make your code like this:


'create new FileSystemObject
Dim fsoMain As New FileSystemObject
Dim strFileName As String
On Error Resume Next


strFileName = "C:\..."

fsoMain.DeleteFile strFileName
If Err Then
Debug.Print Err.Description
End If
'*******end of code<P ID="edit"><FONT class="small"><EM>Edited by cyclonebri on 08/15/01 02:00 PM.</EM></FONT></P>
Reply With Quote
  #5  
Old 08-15-2001, 02:17 PM
KesleyK's Avatar
KesleyK KesleyK is offline
Senior Contributor

Retired Moderator
* Expert *
 
Join Date: Jun 2001
Location: Idaho, missing Dallas
Posts: 965
Default Re: Confused newbie

To change the attributes of a file, use <font color=blue>SetAttr</font color=blue> like this:

For Each f1 in f ' This is part of the files collection in a folder you specify

If GetAttr(f1) <> 0 Then
SetAttr f1, 0
End If

Next


"Recently reported by the Assoc. of Incomplete Research, 7 out of 10 people." -- K. Nealon, SNL
__________________
We shall persevere.
Reply With Quote
  #6  
Old 08-15-2001, 11:52 PM
Alphanumeric's Avatar
Alphanumeric Alphanumeric is offline
Junior Contributor
 
Join Date: Mar 2001
Location: Canada
Posts: 388
Default Re: Confused newbie

The number one reason why you would be getting an error is if there are no files in the History folder. It should give you a File not found error. Is this what you are getting?

<font color=red>ALPHANUMERIC</font color=red>
__________________
ALPHANUMERIC
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->