Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a way to change a readonly file to not readonly? 1

Status
Not open for further replies.

Transcend

Programmer
Sep 29, 2002
858
0
0
AU
Hi there

I've written an application which processes files that are scanned into a directory. Sometimes however the files get placed there from a cd and end up being 'readonly'.

Basically what i want to do is check if a file is readonly and change it before i process it.

Dim dir As DirectoryInfo = New DirectoryInfo(strDrawingLocations)
Dim fsi As FileSystemInfo
Dim strFileName As String
Dim ofos As New Scripting.FileSystemObject()

For Each fsi In dir.GetFileSystemInfos()
If fsi.Attributes.ReadOnly = FileAttributes.ReadOnly Then

End If
Next

what do i put in the If statement to change the readonly property?

Thanks in advance

Transcend
[gorgeous]
 
No it says nothing about file size ...
i think that only hides read only files when using a common dialog box which i'm not using.

I also need to get the filesize too
anyone?

Transcend
[gorgeous]
 
I don't believe your test for read only will return correct results since the FileAttributes property is a summation of all attributes. I think your condition will always return true. Anyhow, this should do the trick

Dim objFileinfo As System.IO.FileInfo
Dim strFilePath As String = "C:\FileName"

objFileinfo = New System.IO.FileInfo(strFilePath)
If objFileinfo.Attributes And IO.FileAttributes.ReadOnly Then
objFileinfo.Attributes = objFileinfo.Attributes - objFileinfo.Attributes.ReadOnly
End If
MessageBox.Show("File Size is: " & objFileinfo.Length & " Bytes")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top