borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Displaying Drive letters)Next Topic (releasing an adodc) New Topic New Poll Post Reply
AndreaVB Forum : VB General : access files properties Solved Topic
Poster Message
humberto
Level: VB Lord

Registered: 13-01-2005
Posts: 246

icon access files properties

How access files properties
and Add custom properties ect..

Thanks

21-03-2006 at 02:50 PM
View Profile Send Email to User Show All Posts | Quote Reply
misterxed
Level: VB Lord


Registered: 12-06-2005
Posts: 151
icon Re: access files properties

Hi.

U can get the properties of a file using following APIs:

GetFileSize
GetFileTime
GetFileAttributes
GetFileType
GetFileVersionInfo
GetFullPathName


What do u mean by custom properties? U can set attributes of a file usiong  SetFileAttributes API

For complete declaration of these API and the structures they use, use the API viewer Application that comes with VB...

Hope thats of some use....


____________________________
lOsT...

21-03-2006 at 06:50 PM
View Profile Send Email to User Show All Posts | Quote Reply
humberto
Level: VB Lord

Registered: 13-01-2005
Posts: 246
icon Re: access files properties

What i mean is set file properties summary
properties summary
titel:
subject:
author:

category:

21-03-2006 at 07:23 PM
View Profile Send Email to User Show All Posts | Quote Reply
humberto
Level: VB Lord

Registered: 13-01-2005
Posts: 246
icon Re: access files properties

I want to get /set File Summary Information related to files, e.g., Title, Subject, Comments etc. We can set these properties by right clicking on a file, taking its properties and going to summary section.
I have already tried System.Diagnostics.FileVersionInfo.GetVersionInfo which has several methods and properties to do so but it did'nt work out.

Does any one have any idea how to do this?  

22-03-2006 at 08:37 AM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: access files properties

test this code:


Private Sub Command1_Click()
    Dim objShell As Object
    Dim objFolder As Object
    Dim i As Integer
    Dim strFileName As Object
    
    ' Get the name of the different properties
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.Namespace("C:\myfolder")
    
    ' Display the properties and their values for each file
    For Each strFileName In objFolder.Items
        If strFileName.Name = "myfile.txt" Then
            For i = 0 To 34
                Debug.Print i & vbTab & objFolder.GetDetailsOf(objFolder.Items, i) & ": " & objFolder.GetDetailsOf(strFileName, i)
            Next
        End If
    Next
End Sub


replace "myfile" and "myfolder" with the path and filename you want to test properties, the property list will be displayed in the immediate window

hope this helps...

____________________________
AndreaVB

22-03-2006 at 01:11 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: access files properties

I have improved the code and created a function, you pass the name of file with full path and the function will show a messagebox with the list of all properties and their respective values


Function FileInfo(strFileName As String)
    '********** IMPORTANT **************
    'for this function to work add reference to
    'Microsoft Shell Controls and Automation
    
    'if you don't add reference to Microsoft Shell Controls and Automation
    'then declare objShell, objFolder anf objFile as Object
    Dim objShell As Shell
    Dim objFolder As Folder
    Dim i As Integer
    Dim objFile As ShellFolderItem
    Dim s As String
    Dim strPath As String
    Dim strName As String
    
    ' Get the name of the different properties
    Set objShell = CreateObject("Shell.Application")
    If InStrRev(strFileName, "\") = 0 Then Exit Function
    'extract path from full file name
    strPath = Left(strFileName, InStrRev(strFileName, "\") - 1)
    'extract file name
    strName = Mid(strFileName, InStrRev(strFileName, "\") + 1)
    'create folder object
    Set objFolder = objShell.NameSpace(strPath)
    If objFolder Is Nothing Then Exit Function
    Set objFile = objFolder.Items.Item(strName)
    'cretae string with all file properties
    For i = 0 To 34
        s = s & i & vbTab & objFolder.GetDetailsOf(objFolder.Items, i) & ": " & objFolder.GetDetailsOf(objFile, i) & vbCrLf
    Next
    'show message box with all values of all properties of the file
    MsgBox s
End Function


____________________________
AndreaVB

22-03-2006 at 01:33 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
humberto
Level: VB Lord

Registered: 13-01-2005
Posts: 246
icon Re: access files properties

FileInfo ("c:\testfolder\test.txt")

why is If objFolder Is Nothing

22-03-2006 at 04:42 PM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: access files properties

does the function exit because objFolder is nothing?

in what OS are you testing the code?

does the folder exist?

____________________________
AndreaVB

22-03-2006 at 04:52 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
humberto
Level: VB Lord

Registered: 13-01-2005
Posts: 246
icon Re: access files properties

yes the folder exits

22-03-2006 at 07:58 PM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: access files properties

...and what operating system are you using?

____________________________
AndreaVB

23-03-2006 at 07:11 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
humberto
Level: VB Lord

Registered: 13-01-2005
Posts: 246
icon Re: access files properties

operating system  Is Windows XP Pro

23-03-2006 at 08:50 AM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: access files properties

well, mine too... I've tested the code again and it worked on my PC

did you try with different file names? did you test each of the two codes I've posted? try with the first one...and maybe removing the file name comparison you should be able to see the preoperties of all the files in a specific path...if not tell me where are you getting errors...

did you add reference to "Microsoft Shell Controls and Automation" that should point to SHELL32.DLL

if not remove the explicit declarations and declare every variable as Object

please let me know how it goes

[Edited by admin on 23-03-2006 at 10:28 AM GMT]

____________________________
AndreaVB

23-03-2006 at 09:24 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
humberto
Level: VB Lord

Registered: 13-01-2005
Posts: 246
icon Re: access files properties

I have  try the 2 ways

1) When reference to "Microsoft Shell Controls and Automation" that should point to SHELL32.DLL

I get Compile err:
Method or data member not found
Set objFile = objFolder.Items.Item(strName)

2)explicit declarations and declare every variable as Object
  objFolder is nothing alway

23-03-2006 at 09:41 AM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: access files properties

is the path to the file correct? are you sure that the file and folder exists on your PC?

just try "C:\boot.ini" and see if it works...

I don't know what else it could be...
if it doesn't work I'll attach a simple project

____________________________
AndreaVB

23-03-2006 at 10:14 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
humberto
Level: VB Lord

Registered: 13-01-2005
Posts: 246
icon Re: access files properties

yes i sure i have create the folder again
i have try with "C:\boot.ini"

and  it doesn't work

23-03-2006 at 10:45 AM
View Profile Send Email to User Show All Posts | Quote Reply
humberto
Level: VB Lord

Registered: 13-01-2005
Posts: 246
icon Re: access files properties

I just find why it not working in my project
a reference to the microsoft script control
it look then they not working together in one project

23-03-2006 at 11:07 AM
View Profile Send Email to User Show All Posts | Quote Reply
humberto
Level: VB Lord

Registered: 13-01-2005
Posts: 246
icon Re: access files properties

Dim objFolder As Shell32.Folder2

23-03-2006 at 11:27 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB General : access files properties Solved Topic
Previous Topic (Displaying Drive letters)Next Topic (releasing an adodc) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder