スクリプトでファイルのプロパティを取得する

0017

10万ファイルくらいのJPGの中から、特定のファイルサイズの物だけを抜き出せますか?と今日聞かれてちょっと調べてみました。

VBScriptでも、結構有用な情報を表示させる事が出来るようです。
Windows Server 2008上でもVBScriptはまだまだ動きますので、運用周りであればまだまだ実用的に使えそうです。

'実行例:Cscript ShowFilesPropaty.vbs ディレクトリ名"
Option Explicit

Dim objArgs
Set objArgs = WScript.Arguments

If objArgs.count = 1 Then  
	GET_DETAILS(objArgs.item(0))
Else 
	Wscript.Echo "引数が不正です。" & vbCrLf & "実行例:Cscript ShowFilesPropaty.vbs ディレクトリ名"
	Wscript.Quit '終了
End If

Sub GET_DETAILS(strPATH)
	Dim arrHeaders(35)
	Dim objShell
	Dim objFolder
	Dim i
	
	Dim strFileName
	
	Set objShell = CreateObject("Shell.Application")
	Set objFolder = objShell.Namespace(strPATH)

	For i = 0 to 34
		arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i)
	Next

	For Each strFileName in objFolder.Items
		For i = 0 to 34
			If objFolder.GetDetailsOf(strFileName, i) <> "" Then
				WScript.StdOut.WriteLine i & vbtab & arrHeaders(i) & ": " & objFolder.GetDetailsOf(strFileName, i)
			End If
		Next
		
		WScript.StdOut.WriteLine "--------------------"
	Next
End Sub

' ファイルプロパティ詳細
' 0 = Name
' 1 = Size
' 2 = Type
' 3 = Date Modified
' 4 = Date Created
' 5 = Date Accessed
' 6 = Attributes
' 7 = Status
' 8 = Owner
' 9 = Author
'10 = Title
'11 = Subject
'12 = Category
'13 = Pages
'14 = Comments
'15 = Copyright
'16 = Artist
'17 = Album Title
'18 = Year
'19 = Track Number
'20 = Genre
'21 = Duration
'22 = Bit Rate
'23 = Protected
'24 = Camera Model
'25 = Date Picture Taken
'26 = Dimensions
'27 = Not used
'28 = Not used
'29 = Not used
'30 = Company
'31 = Description
'32 = File Version
'33 = Product Name
'34 = Product Version


'参考
'Retrieving Extended File Properties
'http://www.microsoft.com/technet/scriptcenter/guide/sas_fil_lunl.mspx?mfr=true

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です