Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Reading file properties  (Read 11856 times)

0 Members and 1 Guest are viewing this topic.

Yogesh123

    Topic Starter


    Beginner

    Reading file properties
    « on: September 29, 2009, 07:00:33 AM »
    Using batch script how to read properties of a perticular file,

    Properties like = Last-Modified date, Modified time, file extension, attributes, size, path, name etc..

    please advise,
    Thanx in advance

    Etherel15



      Starter

      Re: Reading file properties
      « Reply #1 on: October 05, 2009, 07:12:15 PM »
      I'm no genius, but maybe you can use the For command, and then use the "%~tI" variable, or some of the other offshoots, (instead of %%I) to call up file properties, and then just tell it to ECHO them?

      billrich

      • Guest
      Re: Reading file properties
      « Reply #2 on: October 05, 2009, 08:28:59 PM »
       :D
      « Last Edit: October 14, 2009, 07:56:29 AM by billrich »

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: Reading file properties
      « Reply #3 on: October 06, 2009, 02:05:39 AM »
      um... yeah... not sure what that has to do with the OP's query...
      I was trying to dereference Null Pointers before it was cool.

      billrich

      • Guest
      Re: Reading file properties
      « Reply #4 on: October 06, 2009, 02:59:39 AM »
       :D
      « Last Edit: October 14, 2009, 07:57:03 AM by billrich »

      gh0std0g74



        Apprentice

        Thanked: 37
        Re: Reading file properties
        « Reply #5 on: October 06, 2009, 07:12:26 AM »
        @bill, environment variables or attrib doesn't really provide you file properties details. even with dir, it can't get things like creation date, accessed date.

        @OP, you can try using vbscript

        Code: [Select]
        Set objFS=CreateObject("Scripting.FileSystemObject")
        strFileName = WScript.Arguments(0)
        Set objFile = objFS.GetFile(strFileName)
        WScript.Echo "Date last created: " & objFile.DateCreated
        WScript.Echo "Date last modified: " & objFile.DateLastModified
        WScript.Echo "Date last accessed: " & objFile.DateLastAccessed
        WScript.Echo "File size(bytes): " & objFile.Size
        WScript.Echo "File type: " & objFile.Type

        save as myscript.vbs and on command line:
        Code: [Select]
        C:\test>cscript /nologo myscript.vbs test.vbs
        Date last created: 8/8/2009 8:20:36 AM
        Date last modified: 10/6/2009 9:15:44 PM
        Date last accessed: 10/6/2009 9:15:44 PM
        File size(bytes): 8943
        File type: VBScript Script File


        BC_Programmer


          Mastermind
        • Typing is no substitute for thinking.
        • Thanked: 1140
          • Yes
          • Yes
          • BC-Programming.com
        • Certifications: List
        • Computer: Specs
        • Experience: Beginner
        • OS: Windows 11
        Re: Reading file properties
        « Reply #6 on: October 06, 2009, 10:16:07 AM »
        Yes and "um...yeah" is the perfect solution for Yogesh123, the original poster's question?


        I never said it did. If you don't know *censored* your talking about don't post. that is WHY I hadn't posted before- because I don't know a solution, until your post that has absolutely no information of value, in the same way that a person might respond to a post consisting of a copy-paste from Excel help.

        Quote
        The environmental variables and the CMD commands contain the file properties information Yogesh123 is seeking.
        no. They don't. Last-Modified date, Modified time, file extension, attributes, size, path, name- of those, I would guess that the file extension, path, and name are easily available... Oh, and with /t you can get the accessed/modified/created dates. and size.... hey wait a second, you can get all of this info from cmd... But that doesn't change the fact that showing a copy-paste from cmd of you setting and echoing environment variables and listing them is irrelevant.

        Also, it can be tricky to parse the exact wanted field from dir, especially given localization concerns. That being said although your original post was a tad odd the concept you then fleshed out was not off the mark at all.

        I was trying to dereference Null Pointers before it was cool.

        billrich

        • Guest
        Re: Reading file properties
        « Reply #7 on: October 07, 2009, 10:18:35 AM »
         :D
        « Last Edit: October 14, 2009, 07:57:39 AM by billrich »

        billrich

        • Guest
        Re: Reading file properties
        « Reply #8 on: October 07, 2009, 12:14:13 PM »
         :)
        « Last Edit: October 14, 2009, 07:57:55 AM by billrich »

        wbrost



          Intermediate
        • Thanked: 11
          Re: Reading file properties
          « Reply #9 on: October 07, 2009, 12:38:41 PM »
          you replace test.vbs with the file you are looking for the info on.

          if you wanted to check out test.txt

          Code: [Select]
          cscript.exe  /nologo myscript.vbs test.txt

          billrich

          • Guest
          Re: Reading file properties
          « Reply #10 on: October 07, 2009, 02:07:11 PM »
           :)
          « Last Edit: October 14, 2009, 07:58:19 AM by billrich »

          gh0std0g74



            Apprentice

            Thanked: 37
            Re: Reading file properties
            « Reply #11 on: October 07, 2009, 05:55:08 PM »

            But it did not  show the path.
            it doesn't take one to quickly find out the way to show Path. I will spoonfeed you for a liitle. try objFile.Path or read the vbscript manual in my sig.

            Quote
            And I would to see file property information done with a batch file.
            if you are talking about PURE batch cmd.exe commands plus those command line tools (excluding cscript.exe ) that comes natively with windows, no, not in my life time. i will leave that privilege to someone else who has time to spare and brain cells to kill

            billrich

            • Guest
            Re: Reading file properties
            « Reply #12 on: October 07, 2009, 09:07:39 PM »
             :)
            « Last Edit: October 14, 2009, 07:58:46 AM by billrich »

            gh0std0g74



              Apprentice

              Thanked: 37
              Re: Reading file properties
              « Reply #13 on: October 07, 2009, 11:42:26 PM »
              First, the type of file is not the file name. It should give "PDf file" for a file with .pdf extension. Or "Gif file" for .gif extension. If the file is a shortcut, it should display, "shortcut to <whatever original file> "

              secondly, you need 3 separate dir commands to show creation, accessed and modified date. if the directory is big with many files and subfolders, it will take 3 times longer to show every files' properties. unless there's a way to combine showing these 3 date types, that's how inflexible it is. you are not able to control how you program.

              here's a more detailed version recursively going through the directory to get file properties
              Code: [Select]
              Set objFS=CreateObject("Scripting.FileSystemObject")
              strComputer = "."
              Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
              strFolder= "c:\\test\\"
              Set objFolder = objFS.GetFolder(strFolder)
              Go (objFolder)
              Sub Go(objDIR)
                If objDIR <> "\System Volume Information" Then
                  For Each eFolder in objDIR.SubFolders
                    Go eFolder
                  Next
              For Each strFile In objDIR.Files
              name=Replace(strFile.Path,"\","\\")
              s="Select * from CIM_Datafile Where name = '"& name & "'"
              Set colFiles = objWMIService.ExecQuery(s)
              For Each objFile in colFiles
                  Wscript.Echo "Access mask: " & objFile.AccessMask
                  Wscript.Echo "Archive: " & objFile.Archive
                  Wscript.Echo "Compressed: " & objFile.Compressed
                  Wscript.Echo "Compression method: " & objFile.CompressionMethod
                  Wscript.Echo "Creation date: " & objFile.CreationDate
                  Wscript.Echo "Computer system name: " & objFile.CSName
                  Wscript.Echo "Drive: " & objFile.Drive
                  Wscript.Echo "8.3 file name: " & objFile.EightDotThreeFileName
                  Wscript.Echo "Encrypted: " & objFile.Encrypted
                  Wscript.Echo "Encryption method: " & objFile.EncryptionMethod
                  Wscript.Echo "Extension: " & objFile.Extension
                  Wscript.Echo "File name: " & objFile.FileName
                  Wscript.Echo "File size: " & objFile.FileSize
                  Wscript.Echo "File type: " & objFile.FileType
                  Wscript.Echo "File system name: " & objFile.FSName
                  Wscript.Echo "Hidden: " & objFile.Hidden
                  Wscript.Echo "Last accessed: " & objFile.LastAccessed
                  Wscript.Echo "Last modified: " & objFile.LastModified
                  Wscript.Echo "Manufacturer: " & objFile.Manufacturer
                  Wscript.Echo "Name: " & objFile.Name
                  Wscript.Echo "Path: " & objFile.Path
                  Wscript.Echo "Readable: " & objFile.Readable
                  Wscript.Echo "System: " & objFile.System
                  Wscript.Echo "Version: " & objFile.Version
                  Wscript.Echo "Writeable: " & objFile.Writeable
                  WScript.Echo "Install Date: " & objFile.InstallDate
                                  Wscript.Echo "-----------------------------------------------------------------"
              Next
              Next
                End If 
              End Sub


              billrich

              • Guest
              Re: Reading file properties
              « Reply #14 on: October 08, 2009, 09:03:52 AM »
               :D
              « Last Edit: October 14, 2009, 07:55:32 AM by billrich »