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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing to Image file properties script assistance please

Status
Not open for further replies.

xeeva

Technical User
Jun 14, 2011
3
AU
Hi Everyone

Ok. Script function assistance please

Requirements:-
Must not use external DLL's outside of Windows 7
Recursively work through a set of Folders from a defined root
For each Image file Read the last character of the filename and write the TAG property to the file based on conditions as below
If name ends with "0" set the tag to Tree for example

I pretty much have most of this covered, apart from the actual setting the TAG attribute for a file. From what I can find, there is no way to set the file attribute using the method that I am using to retrieve it. My portion of code working on the file information is below

Const conType0 = "Tree"
Const conType1 = "Rock"
Const conType2 = "Sea"
Const conType3 = "Sand"
Const conType4 = "Face"
Const conType5 = "Pool"
Const conType6 = "Car"
Const conType7 = "Bike"
Const conType8 = "Steel"
Const conType9 = "Mud"

strPath = "C:\FaceShop\New folder\images"

Set objAppShell = CreateObject("Shell.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFolder = objAppShell.NameSpace(strPath)
Set objFolderItems = objFolder.Items()

For Each objItem in objFolderItems
varTAG = objFolder.GetDetailsOf(objItem, 18)
varFullNAME = objFolder.GetDetailsOf(objItem, 0)
varFileName = objFSO.GetBaseName(objItem)
varFileconType = Right(varFileName,1)
Select Case varFileconType
Case 0 wscript.echo "File Name is: " & varFileName & " - Setting the Tag to - " & conType0
Case 1 wscript.echo "File Name is: " & varFileName & " - Setting the Tag to - " & conType1
Case 2 wscript.echo "File Name is: " & varFileName & " - Setting the Tag to - " & conType2
Case 3 wscript.echo "File Name is: " & varFileName & " - Setting the Tag to - " & conType3
Case 4 wscript.echo "File Name is: " & varFileName & " - Setting the Tag to - " & conType4
Case 5 wscript.echo "File Name is: " & varFileName & " - Setting the Tag to - " & conType5
Case 6 wscript.echo "File Name is: " & varFileName & " - Setting the Tag to - " & conType6
Case 7 wscript.echo "File Name is: " & varFileName & " - Setting the Tag to - " & conType7
Case 8 wscript.echo "File Name is: " & varFileName & " - Setting the Tag to - " & conType8
Case 9 wscript.echo "File Name is: " & varFileName & " - Setting the Tag to - " & conType9
End Select
Next


 
I've never heard of the TAG property, let alone the .GetDetailsOf method. As the following link suggests, it is part of the shell32.dll file. Also, there doesn't seem to be iColumn of 18, only -1 to 4. varTAG = objFolder.GetDetailsOf(objItem, [red]18[/red])


-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
You may also want to use an [green]array for your types[/green]. If by TAG you mean [red]changing the file name[/red]

Code:
[green]
dim arrTypes(9)
arrTypes(0) = "Tree"
arrTypes(1) = "Rock"
arrTypes(2) = "Sea"
arrTypes(3) = "Sand"
arrTypes(4) = "Face"
arrTypes(5) = "Pool"
arrTypes(6) = "Car"
arrTypes(7) = "Bike"
arrTypes(8) = "Steel"
arrTypes(9) = "Mud"
[/green]
strPath = "C:\FaceShop\New folder\images"

Set objFSO = CreateObject("Scripting.FileSystemObject")

For Each objFile in objFSO.GetFolder(strPath).Files
   'get the last character of the file name (assumes files are in the file.ext format) 
   intFileType = mid(objFile.Name, inStrRev(objFile.Name) - 1, 1)
   wscript.echo "File Name is: " & objFile.Name & " - Setting the Tag to - " & [green]arrTypes(intFileType)[/green]
   [red]objFile.Name = left(objFile.Name, len(objFile.Name) - 1) & arrTypes(intFileType)[/red]
Next

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
>If by TAG you mean changing the file name

Np, the OP is referring to one of the extended properties the shell can display for folder items. "Tags" is one of many new extended properties introduced in Vista.

Sadly, I don't know of any easy way of directly writing these extended properties through VBScript.
 
Also, there doesn't seem to be iColumn of 18, only -1 to 4.
The documentation page you linked to only goes to 4, but there is useful information in the higher numbers. One time I needed to get the duration of .avi files; to get this information I used .GetDetailsOf(objFile, 21). I believe the permissible range will depend on the type of file that is being inspected (ie a .jpg wouldn't have a duration property).
 
Interesting. So these properties are not native to VBS but can be accessed via modular inclusion (eg shell32.dll)? If so, is there a special command to include these files or is that handled by the OS?

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Yes, I need to write to the TAG property of an image file. The Shell32 extension can read this information. Other applications can write to this area, but I need to register and call an external DLL to do that. I would like to avoid that if possible so that the code base is contained within the script to maintain portability.

 
As I say, without external libraries, VBscript cannot do this
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top