Link to home
Create AccountLog in
Avatar of Zack
ZackFlag for Australia

asked on

VBScript - Copy files of a specific image bit depth.

Heyas,

Is there a way using Vbscript to copy files that have specific image bit depth?

Thank you
Avatar of RobSampson
RobSampson
Flag of Australia image

Hi, this script should work for you.  It uses GetDetailsOf to read attribute number 160 of each file in strSourceFolder, and if it's 24, it copies the file to strTargetFolder.

Regards,

Rob,

If LCase(Right(Wscript.FullName, 11)) = "wscript.exe" Then
    strPath = Wscript.ScriptFullName
    strCommand = "%comspec% /k cscript  """ & strPath & """"
    Set objShell = CreateObject("Wscript.Shell")
    objShell.Run(strCommand), 1, True
    Wscript.Quit
End If
 
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
Set colSystemInfo = objWMIService.ExecQuery _
    ("Select Caption from Win32_OperatingSystem",,48)
For Each objItem In colSystemInfo
	strOS_Caption = objItem.Caption
Next
 
If InStr(strOS_Caption, "XP") = 0 Then
	' Vista and Windows 7 has 267 attributes
	ATTRIBUTE_COUNT = 266
Else
	' XP has 41 attributes
	ATTRIBUTE_COUNT = 40
End If

' Bit Depth = attribute 160

strSourceFolder = "C:\Temp"
strTargetFolder = "C:\Temp\New"

If Right(strSourceFolder, 1) = "\" Then strSourceFolder = Left(strSourceFolder, Len(strSourceFolder) - 1)
If Right(strTargetFolder, 1) = "\" Then strTargetFolder = Left(strTargetFolder, Len(strTargetFolder) - 1)

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(strSourceFolder)
If (Not objFolder Is Nothing) Then
	For Each strFileName In objFolder.Items
		If objFolder.GetDetailsOf(strFileName, 160) = "24" Then
			WScript.Echo strFileName
			objFSO.CopyFile strFileName, strTargetFolder & "\", True
		End If
		'For intItem = 0 To ATTRIBUTE_COUNT
		'	strResults = strResults & vbCrLf & "(" & intItem & ") " & objFolder.GetDetailsOf(objFolder.Items, intItem) & ": " & objFolder.GetDetailsOf(strFileName, intItem)
		'Next
	Next
End If
Set objFolder = Nothing
Set objShell = Nothing
'WScript.Echo strResults

Open in new window

Avatar of Zack

ASKER

Hi ,

Thanks for the script but could you explain how it functions.

What this section doing for instance:

If LCase(Right(Wscript.FullName, 11)) = "wscript.exe" Then
    strPath = Wscript.ScriptFullName
    strCommand = "%comspec% /k cscript  """ & strPath & """"
    Set objShell = CreateObject("Wscript.Shell")
    objShell.Run(strCommand), 1, True
    Wscript.Quit
End If
 

Also does Windows 7 have the same of attributes as Vista in reference to the section below:

' Vista has 267 attributes
      ATTRIBUTE_COUNT = 266
Sorry, I had the strFile reference in for testing.  It's not required, so I have removed it.

As for the top 7 seven lines, it just makes sure the script runs under the cscript engine, rather than wscript.  If you don't care about that, you can remove those 7 lines.

Also, as far I can see, Vista and above have the same number of attributes for GetDetailsOf

Regards,

Rob.
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Zack

ASKER

Thank you for the advice.
No problem. Thanks for the grade.

Regards,

Rob.