Windowsのコマンドラインからファイルのメタデータを取得する方法はありますかXP以上ですか?
特に、Windows 7のファイルの[プロパティ]ダイアログの[詳細]タブ(XPの[バージョン]タブ)に通常表示される情報に興味があります。両方のスクリーンショットを以下に示します。私が求めているものの。
可能であれば、cmd.exe
またはWindowsに標準で付属している他の何かXP SP3以上。これが不可能な場合は、次の方法をお勧めします。
Windows XPスクリーンショット:
Windows 7のスクリーンショット:
WMIC.exe を使用して、ほとんどの方法を実行できます。
C:\> wmic datafile where Name = "C:\\ Windows \\ System32 \\ cmd.exe" get Manufacturer、Name、Version Manufacturer Name Version Microsoft Corporation c:\ windows\system32\cmd.exe 6.1.7601.17514
バックスラッシュのエスケープに注意してください\
パス内(それ以外の場合は機能しません)。
探しているものは、 dsofile.dll (Officeがインストールされている場合は不要)と autoit または任意の.NET言語の組み合わせで取得できます。
powershell メソッドも見つけましたが、テストすることができませんでした。
Autoitを使って小さなスクリプトを書きましたが、まだ少し調整が必要です。私はVistaを使用していて、期待どおりに機能するようにいくつかのdsofile.dll呼び出しを取得できませんが、関心のある出力がいくつか提供されます。アクセスできるようになった朝、これについてさらに作業しますXP and win7VM。dll関数のパスをdsofile.dllをインストールする場所に変更する必要があることに注意してください。
#include <file.au3>
Dim $file, $objFile, $Path, $encoding, $attrib, $attributes, $dt, $stamp, $szDrive, $szDir, $szFName, $szExt
If $CmdLine[0] = 0 Then
ConsoleWrite("You must specify a file")
Else
$file = $CmdLine[1]
If FileExists($file) Then
_DLLstartup()
$objFile = ObjCreate("DSOFile.OleDocumentProperties")
If Not IsObj($objFile) Then Exit
$objFile.Open(FileGetLongName($file))
$Path = _PathSplit($file, $szDrive, $szDir, $szFName, $szExt)
ConsoleWrite("Filename: " & $Path[3] & $Path[4] & @CRLF)
ConsoleWrite("Size: " & FileGetSize($file) & " bytes" & @CRLF)
ConsoleWrite("Version: " & FileGetVersion($file) & @CRLF)
ConsoleWrite("Company: " & $objFile.SummaryProperties.Company & @CRLF)
ConsoleWrite("Author: " & $objFile.SummaryProperties.Author & @CRLF)
$encoding = FileGetEncoding($file)
Select
Case $encoding = 0
$encoding = "ANSI"
Case $encoding = 32
$encoding = "UTF16 Little Endian"
Case $encoding = 64
$encoding = "UTF16 Big Endian"
Case $encoding = 128
$encoding = "UTF8 (with BOM)"
Case $encoding = 256
$encoding = "UTF8 (without BOM)"
EndSelect
ConsoleWrite("Encoding: " & $encoding & @CRLF)
$attrib = FileGetAttrib($file)
$attributes = ""
If StringInStr($attrib, "R") <> 0 Then
$attributes = $attributes & " READONLY"
EndIf
If StringInStr($attrib, "A") <> 0 Then
$attributes = $attributes & " ARCHIVE"
EndIf
If StringInStr($attrib, "S") <> 0 Then
$attributes = $attributes & " SYSTEM"
EndIf
If StringInStr($attrib, "H") <> 0 Then
$attributes = $attributes & " HIDDEN"
EndIf
If StringInStr($attrib, "N") <> 0 Then
$attributes = $attributes & " NORMAL"
EndIf
If StringInStr($attrib, "D") <> 0 Then
$attributes = $attributes & " DIRECTORY"
EndIf
If StringInStr($attrib, "O") <> 0 Then
$attributes = $attributes & " OFFLINE"
EndIf
If StringInStr($attrib, "C") <> 0 Then
$attributes = $attributes & " COMPRESSED"
EndIf
If StringInStr($attrib, "T") <> 0 Then
$attributes = $attributes & " TEMPORARY"
EndIf
ConsoleWrite("Attributes:" & $attributes & @CRLF)
$dt = FileGetTime($file, 1)
$stamp = $dt[0] & "-" & $dt[1] & "-" & $dt[2] & " " & $dt[3] & ":" & $dt[4] & ":" & $dt[5]
ConsoleWrite("Created: " & $stamp & @CRLF)
$dt = FileGetTime($file, 0)
$stamp = $dt[0] & "-" & $dt[1] & "-" & $dt[2] & " " & $dt[3] & ":" & $dt[4] & ":" & $dt[5]
ConsoleWrite("Accessed: " & $stamp & @CRLF)
$dt = FileGetTime($file, 2)
$stamp = $dt[0] & "-" & $dt[1] & "-" & $dt[2] & " " & $dt[3] & ":" & $dt[4] & ":" & $dt[5]
ConsoleWrite("Modified: " & $stamp & @CRLF)
ConsoleWrite("Short Name: " & FileGetShortName($file, 1) & @CRLF)
ConsoleWrite("Long Name: " & FileGetLongName($file, 1))
$objFile.Close
_DLLshutdown()
Else
ConsoleWrite("Can't find file")
EndIf
EndIf
Func _DLLstartup($DLLpath = '') ;borrowed from Andrew Goulart
If $DLLpath = Default Or $DLLpath = '' Then $DLLpath = "C:\DsoFile\dsofile.dll";@ScriptDir & '\dsofile.dll'
ShellExecuteWait('regsvr32', '/s /i ' & $DLLpath, @WindowsDir, 'open', @SW_HIDE)
EndFunc
Func _DLLshutdown($DLLpath = '') ;borrowed from Andrew Goulart
If $DLLpath = Default Or $DLLpath = '' Then $DLLpath = "C:\DsoFile\dsofile.dll";@ScriptDir & '\dsofile.dll'
ShellExecuteWait('regsvr32', ' /s /u ' & $DLLpath, @WindowsDir, 'open', @SW_HIDE)
EndFunc
上記の@bobbymcrの回答を拡張するだけです(私は非常に役に立ちました、ありがとう!)。 LIST BRIEF
またはLIST FULL
オプションを使用すると、コマンドを簡略化して結果を広げることができます。
詳細については、> wmic datafile list /?
を確認してください。
このソリューションは私を助けました:> wmic datafile "c:\\path\\to\\file.exe" list full
注: @bobbymcrで述べたように、\
をエスケープすることを忘れないでください。エスケープしないと機能しません。