Solved

Setting/Changing File Custom Properties using VBScript

Posted on 2004-09-17
5
644 Views
Last Modified: 2012-06-21
Hi

I am currently working on a (.vbs) script to migrate files from an old version to a new one. I want to set Custom File Properties for some of the files using the script. I know that Visual Basic has a couple of ways of doing this. But can someone tell me if they (or any other method) work with VBScript

Thanks

Prasad
0
Comment
Question by:PrasadViswanathan
  • 2
  • 2
5 Comments
 
LVL 13

Expert Comment

by:Michael_D
ID: 12086706
What "Custom Properties" do you mean?

Here is sample from MSDN shows how to set file attributes? Is it what you want?

Sub SetClearArchiveBit(filespec)
    Dim fs, f, r
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFile(fs.GetFileName(filespec))
    If f.attributes and 32 Then
        r = MsgBox("The Archive bit is set, do you want to clear it?", vbYesNo, "Set/Clear Archive Bit")
        If r = vbYes Then
            f.attributes = f.attributes - 32
            MsgBox "Archive bit is cleared."
        Else
            MsgBox "Archive bit remains set."
        End If
    Else
        r = MsgBox("The Archive bit is not set. Do you want to set it?", vbYesNo, "Set/Clear Archive Bit")
        If r = vbYes Then
            f.attributes = f.attributes + 32
            MsgBox "Archive bit is set."
        Else
            MsgBox "Archive bit remains clear."
        End If
    End If
End Sub

0
 
LVL 13

Expert Comment

by:Michael_D
ID: 12086739
you can look here to see which file properties available using FSO

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/jsobjfile.asp
0
 
LVL 76

Accepted Solution

by:
David Lee earned 250 total points
ID: 12087836
Custom File Properties makes me think you're talking about document properties instead of file properties.  If so, then you can use DSO to get to the document properties of an Office document.  Here's a link to where you can get the DSO object.

http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q224/3/51.asp&NoWebContent=1

Here's a link to another EE question that contains a DSO example: http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20794252.html

Look for the post:

Comment from g0rath
Date: 11/11/2003 09:46AM EST
0
 

Author Comment

by:PrasadViswanathan
ID: 12107844
Thank you all for your comments. The file "Custom Properties" I was referring to is the "Custom Properties" TAB that you get when you right click the file and go to properties. I will try the DSO and let you know. Thanks again for the quick replies.

Prasad
0
 

Author Comment

by:PrasadViswanathan
ID: 12125478
The DSO example didn't exactly work as given on that site, but it helped a great deal to point me in the right direction. This is the code I used that worked.

'***************************************************************
'Set the Document Property Reader and read properties of a file.
'***************************************************************

sFile = "Test File.xls"
Set oFilePropReader = CreateObject("DSOleFile.PropertyReader")
Set oDocProp = oFilePropReader.GetDocumentProperties(sFile)

'***************************************************************
'Set the Custom Properties.
'***************************************************************
oDocProp.CustomProperties.Add "Source_Name", False
oDocProp.CustomProperties.Item("Source_Name").Value = "somefilename.xls"

But I'll accept that answer :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now