File Attributes

How can I get attributes of a file

Page 1 of 1

5 Replies - 27977 Views - Last Post: 29 July 2007 - 09:52 PM Rate Topic: -----

#1 Narendrass  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-June 07

File Attributes

Posted 19 June 2007 - 07:22 AM

I am trying to get attributes of File or directory using vb.net 2005. I am using GetFileAttributesEx. But some how it is not giving me proper info.
can some one help me with getting file information.

Regards,

Narendra Shetty.
Is This A Good Question/Topic? 0
  • +

Replies To: File Attributes

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: File Attributes

Posted 19 June 2007 - 11:43 AM

Can you show how you're using it?
Was This Post Helpful? 0
  • +
  • -

#3 alsaan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-June 07

Re: File Attributes

Posted 19 June 2007 - 11:45 AM

Take a look at System.IO.FileInfo and System.IO.DirectoryInfo

For example, to get the size of a file you'd do something like this:
Dim fileSize as Long = New System.IO.FileInfo("C:\path\to\file.txt").Lenght


To get the creation time of a directory:
Dim creationTime as Date = New System.IO.DirectoryInfo("C:\path\to\dir").CreationTime



Hope that helps

Cheers

This post has been edited by alsaan: 19 June 2007 - 11:48 AM

Was This Post Helpful? 0
  • +
  • -

#4 Narendrass  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-June 07

Re: File Attributes

Posted 19 June 2007 - 11:24 PM

I am using something like this
Dim ret As Long, i As Integer
Dim w As WIN32_FILE_ATTRIBUTE_DATA
ret = GetFileAttributesEx("c:\", 0, w)

here I am confused with second parameter to getFileAttributesEx function.

Also I need to know how can I see the attributes values.
I basically want to check if the file is compressed or not.
Regards,

Narendra Shetty.
Was This Post Helpful? 0
  • +
  • -

#5 alsaan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-June 07

Re: File Attributes

Posted 20 June 2007 - 02:19 PM

	Function IsCompressed(ByVal filePath As String) As Boolean

		Dim attrib As System.IO.FileAttributes = System.IO.File.GetAttributes(filePath)

		If (attrib And System.IO.FileAttributes.Compressed) = System.IO.FileAttributes.Compressed Then
			Return True
		Else
			Return False
		End If

	End Function 

Was This Post Helpful? 0
  • +
  • -

#6 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: File Attributes

Posted 29 July 2007 - 09:52 PM

I agree with the others, using the System.IO.FileInfo is really the preferred way of getting file attributes (over GetFileAttributesEx).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1