1.

Solve : Reading file properties?

Answer»

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.Quote from: billrich on October 08, 2009, 09:03:52 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....
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.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 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 pieQuote 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. 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
Good Luck(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).

SidewinderThis thread is better than many TV soaps.
Good job Sidewinder. I'm SORRY I took up too much of your time.

Keep posting; you know what you are talking about.Quote from: billrich on October 10, 2009, 12:15:00 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"...

Quote from: billrich on October 10, 2009, 12:15:00 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
-----------------------------------------------------------------











Discussion

No Comment Found