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
|
humberto Level: VB Lord Registered: 13-01-2005 Posts: 246
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
|
humberto Level: VB Lord Registered: 13-01-2005 Posts: 246
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.
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
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
|
humberto Level: VB Lord Registered: 13-01-2005 Posts: 246
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
|
humberto Level: VB Lord Registered: 13-01-2005 Posts: 246
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