delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2014/01/01/17:34:29

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:mime-version:in-reply-to:references:date
:message-id:subject:from:to:content-type
:content-transfer-encoding; q=dns; s=default; b=PIOVo/URukVDMc2/
gpnMuuGjDmU5TLassIUc1wIYZwdtXLxr/hCFWxpSuWgelxMUtTvBciSwwA7JPsWT
qPJFbo0A5e2zlFyXyMAwAJvnN1CbTjP0mYsL0hrZyVSEVxN2OCM0QKXdHm8SFpiV
dKk8laI6uLEV8/jQHsoSgPvBMjQ=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:mime-version:in-reply-to:references:date
:message-id:subject:from:to:content-type
:content-transfer-encoding; s=default; bh=NPew8OInAnWiSZA2K+Iigm
BLkWs=; b=Pf5nSPkvqOrw7mbgmI3U3ZuMuO9ls/wQAlEuEGlTSO1aWoE2qx9thD
lBHFY2qXx9ANGYUxKKCzZssK6OPd1bVK3hVW7Ufv29jxR1anJyJNuBFIz/8VFU5G
VynD7sixDMo4tYACfgG4tfkTHI93aL8HEu10XV+k9s34oYbGggz7s=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=2.5 required=5.0 tests=AWL,BAYES_50,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS,URIBL_BLACK autolearn=no version=3.3.2
X-HELO: mail-lb0-f170.google.com
MIME-Version: 1.0
X-Received: by 10.152.219.133 with SMTP id po5mr17713955lac.34.1388615648029; Wed, 01 Jan 2014 14:34:08 -0800 (PST)
In-Reply-To: <23cd37fc-ba40-4666-81a3-feb46ecfa658@retting.com>
References: <23cd37fc-ba40-4666-81a3-feb46ecfa658 AT retting DOT com>
Date: Wed, 1 Jan 2014 23:34:07 +0100
Message-ID: <CAM9pMnNTs59BCw6yzD--VenC6XSk-Vy_Gmir3NZBgQF3Y4vDPA@mail.gmail.com>
Subject: Re: getting windows ntfs file info
From: Robert Klemme <shortcutter AT googlemail DOT com>
To: Jon Retting <jon AT retting DOT com>, cygwin AT cygwin DOT com
X-IsSubscribed: yes
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id s01MYPKf003106

On Mon, Dec 30, 2013 at 9:22 AM, Jon Retting <jon AT retting DOT com> wrote:
> Hello,
>     Typed up this one liner function for getting a files actual windows details/properties information.  I needed a tertiary way to compare executable/drivers, so a version number from windows seemed like a viable option. Hopefully someone will find this handy, seeing as i feel so guilty for not contributing more to such a wonderful project like Cygwin. And heck anything's better than that most recent dosshell thread :)
>
> #get file details from windows via wmic wmi formatted call condensed
> finfo() { [[ -f "$(cygpath "$@")" ]] || { echo "bad-file";return 1;}; echo "$(wmic datafile where name=\""$(echo "$(cygpath -wa "$@")"|sed 's/\\/\\\\/g')"\" get /value)"|sed 's/\r//g;s/^M$//;/^$/d'|awk -F"=" '{print $1"=""\033[1m"$2"\033[0m"}';}

If I'm not mistaken there is at least one superfluous "echo $(" in
there.  I would also not use $@ since there could be multiple
arguments. IIRC you can also omit quotes around $(...) without risking
issues with multiple words.

finfo() {
  [ -f "$(cygpath -u "$1")" ] || { echo "bad file: $1" >&2; return 1; }

  wmic datafile where name=\"$(cygpath -w "$1" | sed 's/\\/\\\\/g')\"
get /value \
  | sed 's/\r//g;s/^M$//;/^$/d' \
  | awk '-F=' '{printf "%s=\033[1m%s\033[0m\n", $1, $2}'
}

Changed a few more things
 - error to stderr
 - line breaks
 - awk print -> printf

Unfortunately I don't have a cygwin handy to test this. I'd also
probably not output color coding control characters from this function
but rather use tputs to adjust to the terminal at hand. Also sed code
can be integrated into awk or replaced by dos2unix, I guess.

Kind regards

robert


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019