|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to programmatically change directory attributesI'm trying to write a simple VS.NET 2003 VB program to delete files and directories on my hard drive. If the directory is read only, how do i change it's attribute so that i can delete it ? Here is some of my code. It does not error out, it just does not delete the directories. Any help would be gratefully appreciated even ideas on another way to do this. I'm new at all this, so any pointers that any body can give would also be appreciated. Thanks, Tony Try Dim dirsb() As String = Directory.GetFiles("C:\Documents and Settings\Administrator\Local Settings\Temp") For Each dirx In dirsb Directory.Delete(dirx, True) Next Catch ex As Exception Exit Try End Try Something like this should do it
Try Dim dirsb() As String = Directory.GetFiles("C:\Documents and Settings\Administrator\Local Settings\Temp") For Each dirx As String In dirsb Dim info As New DirectoryInfo(dirx) info.Attributes = Not FileAttributes.ReadOnly And info.Attributes Directory.Delete(dirx, True) Next Catch ex As Exception End Try /claes Show quoteHide quote "Tony Girgenti" <TonyGirge***@discussions.microsoft.com> wrote in message news:ABD680C2-F9F5-4320-A190-7AEC98E51C25@microsoft.com... > Hello. > > I'm trying to write a simple VS.NET 2003 VB program to delete files and > directories on my hard drive. If the directory is read only, how do i > change > it's attribute so that i can delete it ? > > Here is some of my code. It does not error out, it just does not delete > the > directories. > > Any help would be gratefully appreciated even ideas on another way to do > this. > I'm new at all this, so any pointers that any body can give would also be > appreciated. > > Thanks, > Tony > > Try > Dim dirsb() As String = Directory.GetFiles("C:\Documents and > Settings\Administrator\Local Settings\Temp") > For Each dirx In dirsb > Directory.Delete(dirx, True) > Next > Catch ex As Exception > Exit Try > End Try >
how do I call a SQL Server stored procedure?
Application.Run Problem blank form when debugging Passing values bewteen user controls is separate web forms Write to an existing ASCII file Newbee ASP.NET Questions Detecting process start Simple data grid question adding BG to forms. Convert local time(eg EST) on local machine to GMT |
|||||||||||||||||||||||