14

Is there any command get all the properties of a file including its encoding format (this piece of information is really important to me) on Windows ? I'm looking for something similar to stat in Linux

I'd prefer using a command that can be used in command-prompt or a batch script although I know its possible with Powershell.

2
  • Which version of Windows?
    – DavidPostill
    Commented Apr 5, 2015 at 11:34
  • Windows Server 2008/ Windows 7 onwards Commented Apr 5, 2015 at 12:28

4 Answers 4

15

You can use WMIC feature to do that.

For example :

F:>> wmic datafile where Name="anyfile.txt"

to get all information about anyfile.txt. You can use CMD and powershell too to using WMIC. And you can use GET parameter to get a specified information.

For Example:

F:>> wmic datafile where Name="F:\\ekojs.txt" get Description,Path,Status,Version

EDIT : Try using this before to check the WMIC functionality :

F:>> wmic datafile /?

To get a help how to using it.

Command :

wmic datafile where Name="F:\\ekojs.txt" get Description,Name,FileType >> eko_wmic.txt

Output in eko_wmic.txt:

Description   FileType       Name          
f:\ekojs.txt  Text Document  f:\ekojs.txt  

Hope this'll help you out..

15
  • 8
    I keep getting an error "No Instance(s) Available" Commented Apr 5, 2015 at 10:47
  • 1
    you run this command using cmd ? or powershell ? Commented Apr 5, 2015 at 10:50
  • 1
    I used "cmd" with Administrative Privileges. wmic datafile /? didn't help :( Can you please edit your answer and give me the exact query you used to get information of some file with the ouput as well. ? Commented Apr 5, 2015 at 11:01
  • 1
    From Dale C: The linked response, superuser.com/questions/1024034/…, has the resolution to “No Instance(s) Available” where the full escaped file path to for the file name has to be used.
    – fixer1234
    Commented Jan 17, 2018 at 22:12
  • 2
    @DhiwakarRavikumar: I ran into the "No Instance(s) Available" error too. I silved it by escaping all backslashes with an extra \.
    – Freeze
    Commented Dec 21, 2018 at 15:25
5

To build on the previous answer. You can use wmic datafile to get info about a file, but you have to provide the full path and double-up your slashes like so

wmic datafile where Name="F:\\anyfile.txt"

This gives an unreadable mess in the console, as you'll see:

what a great way to render data, wmic

However if you pipe this into a text file, it's pretty legible

wmic datafile where Name="F:\\anyfile.txt" >> fileprops.txt

enter image description here

Fortunately, wmic can format the info as a list, and then it is actually pretty useful.

wmic datafile where Name="F:\\anyfile.txt" list /format:list

enter image description here

You can then provide these properties only for a simplified view, note that you must remove the list keyword.

>wmic datafile where Name="G:\\ipcamera.log" get Hidden,FileSize,Name  /format:list


FileSize=20
Hidden=FALSE
Name=G:\ipcamera.log

A little piece of trivia, wmic was the foundation for what eventually became PowerShell!

1
  • 1
    The wmic list display is quite useful; I used to use that same command but without the list part. For info on folders/directories, use wmic FSDIR where Name="C:\\path\\to\\folder" list /format:list. Online docs: ss64.com/nt/wmic.html
    – Rublacava
    Commented Sep 20, 2020 at 1:06
1

You can use any scripting language that can use COM objects such as vbscript and powershell to access a files extended properties (Title, Duration, Frame rate, etc.) using the Shell.Application object. Unfortunately, cmd does not have a direct way to access the Shell object, you will have to piggyback on some other scripting language to access the Shell object.

Running the following command from a cmd prompt window will display the duration of the video file in 100ns units (not milliseconds).

PowerShell -Command "$FilePath='C:\Videos\Test.mp4'; Write-Host ((New-Object -COMObject Shell.Application).NameSpace((Split-Path -Parent -Path $FilePath))).ParseName((Split-Path -Leaf -Path $FilePath)).ExtendedProperty('System.Media.Duration')"

Additional information about the command can be found at Enumerate file properties in PowerShell

0

Just spend two days on trying to write the rating used in the Windows File Explorer through scripting or command line. Reading was easy enough, see the other answers, writing was another matter. Finally found a tool that has a GUI but can also be used from the command line. PropertySystemView from Nirsoft

Example: set the rating of an mp4 to the lowest value

PropertySystemView.exe /SetProperty "d:\test.mp4" "System.Rating" 1

Some other examples:

Export the list of all properties of 1.mp4 file into csv file
PropertySystemView.exe /Filename "c:\temp\1.mp4" /scomma "c:\temp\mp4_properties.csv"
Export the list of all properties on your system into html5 file
PropertySystemView.exe /AllProperties /shtml "c:\temp\all_system_properties.html"
Set the 'Media Created' date/time of single .mp4 file.
PropertySystemView.exe /SetProperty "c:\temp\1.mp4" "System.Media.DateEncoded" "2018/11/23:08:10:30.000"
Set the 'Media Created' date/time of all .mp4 files on c:\myfiles folder
PropertySystemView.exe /SetProperty "c:\myfiles\*.mp4" "System.Media.DateEncoded" "2015/10/15:00:00:00.000"
Copy the value of System.DateCreated property into the System.Media.DateEncoded property
PropertySystemView.exe /CopyProperty "C:\temp\1.mp4" System.DateCreated System.Media.DateEncoded
Remove the comment from all .mp4 files on c:\myfiles folder
PropertySystemView.exe /RemoveProperty "c:\myfiles\*.mp4" "System.Comment"
Set the 'Date Taken' value of all .jpg files on c:\pictures folder
PropertySystemView.exe /SetProperty "c:\pictures\*.jpg" "System.Photo.DateTaken" "2019/11/01:10:00:00.000"
Set the last saved date of the specified Excel file:
PropertySystemView.exe /SetProperty "c:\temp\myfile.xlsx" "System.Document.DateSaved" "2019/10/20:11:22:33.000"
Set the 'Content Created' date/time of the specified Excel file:
PropertySystemView.exe /SetProperty "c:\temp\myfile.xlsx" "System.Document.DateCreated" "2019/01/31:22:59:50.000"
Set the authors of all Excel files on c:\myfiles folder:
PropertySystemView.exe /SetProperty "c:\myfiles\*.xlsx" "System.Author" "NirSoft"
Set the 'Last Saved By' value of all Excel files on c:\myfiles folder:
PropertySystemView.exe /SetProperty "c:\myfiles\*.xlsx" "System.Document.LastAuthor" "NirSoft"
Set the title of Excel file:
PropertySystemView.exe /SetProperty "c:\myfiles\1.xlsx" "System.Title" "This is my Excel file"
Set the 'Last Saved By' value of MS-Word file:
PropertySystemView.exe /SetProperty "c:\myfiles\mydoc.docx" "System.Document.LastAuthor" "NirSoft"
Set the System.AppUserModel.ID property of a window that its handle is 010C0A35 to MyWindow
PropertySystemView.exe /SetPropertyWindow 010C0A35 "System.AppUserModel.ID" "MyWindow"
Open the location of the specified .jpg file in Google Maps:
PropertySystemView.exe /Filename "C:\temp\20200719_090250.jpg" /OpenGoogleMaps

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .