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 11861 times)

0 Members and 1 Guest are viewing this topic.

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 #15 on: October 08, 2009, 09:32:13 AM »
he requested the attributes and dates... however your solution isn't quite there yet, since it still has  the bulky surounding text output from dir and attrib.

I imagine that some weird text manipulation could be achieved in batch though, to get the dates/attributes directly into environment variables.
I was trying to dereference Null Pointers before it was cool.

gh0std0g74



    Apprentice

    Thanked: 37
    Re: Reading file properties
    « Reply #16 on: October 08, 2009, 09:37:25 AM »
    Ghost,

    Since Ghost imports commands from around the world to a Batch Board,
    nowhere in the rules says this forum is just for cmd commands. so suck it up.

    Quote
    I suggest Ghost use Unix( Linux )  commands  "Chmod: or "ls -last" for the attributes of the file.
    chmod doesn't even come close to displaying file properties on linux. do you even understand what chmod does? Does OP want to change file permissions? I doubt so, since he doesn't say in his post. Which unix/linux platform are you on ? i don't recognise -last switch from ls. Also, the proper tools to use in *nix to list file properties are stat (or GNU find with printf ).


    Quote
    The Ghost VBS uses a separate line of code for each attribute.
    look carefully again at the code. for each file listed, it display all the attributes of that file.

    Quote
    Batch only needs attrib.
    bull.. show your batch code then...

    Quote
    By the way, Yogesh123 , the orginal poster,  requested the properties of one file each time and not all the files in the directory or on the the C Drive.
    if he just want a script to pass a file name to it each time, its trivial to change. No big deal. just remove the loops....

    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 #17 on: October 08, 2009, 09:47:30 AM »
    I'm looking... but I see no batch board. I see a "Microsoft DOS" board, which has been already discussed to apply to both pure DOS AND windows-based DOS prompts. This includes the windows scripting host, which was designed to replace, at least in some capacity, Batch files.
    I was trying to dereference Null Pointers before it was cool.

    billrich

    • Guest
    Re: Reading file properties
    « Reply #18 on: October 08, 2009, 11:39:28 AM »
     :D
    « Last Edit: October 14, 2009, 07:53:19 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 #19 on: October 08, 2009, 12:10:53 PM »
    as we say here, shut up and have some pie.


    Ok, actually I'm the only one that says it. but you cannot go wrong with pie.
    I was trying to dereference Null Pointers before it was cool.

    james202428

    • Guest
    Re: Reading file properties
    « Reply #20 on: October 08, 2009, 12:22:29 PM »
    I don't like most kinds of pies i do like pumkin pie with alot of whipcream though there's alot of people who don't like pie

    if america had to agree on one food to eat the rest of there lives in a vote i wonder what it would be i don't think it would be pie

    billrich

    • Guest
    Re: Reading file properties
    « Reply #21 on: October 08, 2009, 01:54:32 PM »
     :D
    « Last Edit: October 14, 2009, 07:50:11 AM by billrich »

    gh0std0g74



      Apprentice

      Thanked: 37
      Re: Reading file properties
      « Reply #22 on: October 08, 2009, 05:12:05 PM »
      Quote from: billrich
      BC_Programmer  talks with great authority but has produced no Batch code or any other code
      he has already said in his post he doesn't know a solution. And if he feels like it and wants to write that code, he will, and he certainly knows what he is talking about.
      « Last Edit: October 08, 2009, 05:31:14 PM by gh0std0g74 »

      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Re: Reading file properties
      « Reply #23 on: October 10, 2009, 09:09:19 AM »
      The easiest solution is Ghostdog's VBScript where you can refer to each property by name and not some hieroglyphic token name.

      However (sigh) if you insist on a batch solution, this is one way:

      Code: [Select]
      @echo off
      set /p fname=Enter file name:
      dir /tc %fname% > dir.txt
      for /f "skip=5 tokens=1" %%v in (dir.txt) do (
        echo Date Created:         %%v
        goto next
        )

      :next 
      dir /ta %fname% > dir.txt
      for /f "skip=5 tokens=1" %%v in (dir.txt) do (
        echo Date Accessed:        %%v
        goto next
        )

      :next 
      dir /tw %fname% > dir.txt
      for /f "skip=5 tokens=1" %%v in (dir.txt) do (
        echo Date Written:         %%v
        goto next
        )
       
      :next 
      dir %fname% > dir.txt
      for /f "skip=5 tokens=5" %%v in (dir.txt) do (
        echo Fully Qualified Name: %%~fv
        echo Drive Specification:  %%~dv
        echo Path Specification:   %%~pv
        echo File Name:            %%~nv
        echo File Extension:       %%~xv
        echo Short Name:           %%~sv
        echo File Attributes:      %%~av
        echo File Date/Time:       %%~tv
        echo File Size:            %%~zv
        goto next
        )
       
      :next
      del dir.txt 
      « Last Edit: October 10, 2009, 09:25:24 AM by Sidewinder »
      The true sign of intelligence is not knowledge but imagination.

      -- Albert Einstein

      billrich

      • Guest
      Re: Reading file properties
      « Reply #24 on: October 10, 2009, 10:32:34 AM »
      Good Luck
      « Last Edit: October 12, 2009, 11:17:17 AM by billrich »

      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Re: Reading file properties
      « Reply #25 on: October 10, 2009, 11:31:28 AM »
      (Sigh) The file I coded does not use a command line parameter, but prompts for the fie name. I'm confused about the file name timeinseconds, when in fact the file reported by the batch file is C:\$WINDOWS.~BT.

      The file name and file extension are correct as reported in the output. The attributes are also correct (directory). I have no idea why size was not reported correctly,except directories do not have size properties (at least from the command prompt).

      Sidewinder
      The true sign of intelligence is not knowledge but imagination.

      -- Albert Einstein

      Salmon Trout

      • Guest
      Re: Reading file properties
      « Reply #26 on: October 10, 2009, 11:47:45 AM »
      This thread is better than many TV soaps.

      billrich

      • Guest
      Re: Reading file properties
      « Reply #27 on: October 10, 2009, 12:15:00 PM »
      Good job Sidewinder.  I'm sorry I took up too much of your time.

      Keep posting;  you know what you are talking about.
      « Last Edit: October 12, 2009, 11:16:08 AM by billrich »

      Salmon Trout

      • Guest
      Re: Reading file properties
      « Reply #28 on: October 10, 2009, 01:18:01 PM »
      I used the snake's code except a command line argument instead of a prompt.

      You and BC are in the same camp:  "All Hat and no Cattle."

      A twinkle in his eye and murder in his trousers, my mother used to say, or "all piss and vinegar"...


      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 #29 on: October 10, 2009, 01:33:56 PM »
      I used the snake's code except a command line argument instead of a prompt.

      You and BC are in the same camp:  "All Hat and no Cattle."

      Ironic. All you've done since your original post is purposely invent situations in which other peoples solutions break. For example by munging the batch file sidewinder provided. It works fine for me.

      Obviously you failed to "convert" it to use a command-line argument, because it works fine here.

      for a icon file I have:

      Quote

      D:\>side
      Enter file name: D:\question.ico
      Date Created:         09/08/2009
      Date Accessed:        09/08/2009
      Date Written:         09/08/2009
      Fully Qualified Name: D:\question.ico
      Drive Specification:  D:
      Path Specification:   \
      File Name:            question
      File Extension:       .ico
      Short Name:           D:\question.ico
      File Attributes:      --a------
      File Date/Time:       09/08/2009 05:39 PM
      File Size:            15086

      D:\>
      It failed when I tried to use it on files from another drive:




      Probably easily fixed with a PushD of some form, since it works from that directory:

      Quote



      D:\>side C:\windows\syswow64\shell32.dll
      Enter file name: C:\windows\syswow64\shell32.dll
      Date Created:         07/30/2009
      Date Accessed:        07/30/2009
      Date Written:         04/10/2009
      Fully Qualified Name: C:\Windows\SysWOW64\shell32.dll
      Drive Specification:  C:
      Path Specification:   \Windows\SysWOW64\
      File Name:            shell32
      File Extension:       .dll
      Short Name:           C:\Windows\SysWOW64\shell32.dll
      File Attributes:      --a------
      File Date/Time:       04/10/2009 11:28 PM
      File Size:            11584000


      In either case perhaps before making alterations to a batch file Billrich should test it as provided, rather then making changes and proclaiming epic failure even when it's fully possible the changes caused the problem, as I believe to be the case here.







      Seems to work fine. Of course I didn't mess about with the innards like a inept surgery intern. I believe the logic at this point speaks for itself for everybody but SpectateSwamp Billrich, who will continue on with analogies that bring back his fond memories of the ranch, and yet have no bearing to the context at all.



      In other news, I also converted (somewhat more successfully then the batch code... which  I didn't mess with at all) the VBS file to access only a single file specified as an argument.

      Code: [Select]
      Set objFS=CreateObject("Scripting.FileSystemObject")
      strComputer = "."
      Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
      strFile= wscript.Arguments(0)
      Set objFile = objFS.GetFile(strFile)
       
      name=Replace(ObjFile.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

       


      This can be accessed in a batch file:

      Code: [Select]

      cscript fileattribs.vbs D:\testads2.txt


      D:\>fileattribs D:\testads2.txt
      Microsoft (R) Windows Script Host Version 5.7
      Copyright (C) Microsoft Corporation. All rights reserved.

      Access mask:
      Archive: True
      Compressed: False
      Compression method:
      Creation date: 20090803234730.934563-420
      Computer system name: TERATRON
      Drive: d:
      8.3 file name: d:\testads2.txt
      Encrypted: False
      Encryption method:
      Extension: txt
      File name: testads2
      File size: 287
      File type: Text Document
      File system name: NTFS
      Hidden: False
      Last accessed: 20090803234730.934563-420
      Last modified: 20090303190457.875000-480
      Manufacturer:
      Name: d:\testads2.txt
      Path: \
      Readable: True
      System: False
      Version:
      Writeable: True
      Install Date: 20090803234730.934563-420
      -----------------------------------------------------------------









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