2011年4月6日水曜日

Excel Viewer のコマンドラインオプション

xlview.exe [/e|(path名)]
  • /e [ファイルを開く] 画面を開かないで起動する。
  • 起動して(path名)のファイルを開く。

確認方法

下記コマンドを順番に実行。

コマンド プロンプト
C:\Program Files\Microsoft Office\Office12\>xlview.exe /a
  :
  :
C:\Program Files\Microsoft Office\Office12\>xlview.exe /z

確認環境

  • Microsoft Windows XP Professional Version 2002 Service Pack 3
  • Microsoft(r) Office Excel Viewer (12.0.6545.5000)

応用

Excel ファイルのパス名か、URL が書かれている一行のファイルを Drag and Drop すると Excel Viewer で開けるようなバッチファイルを書いてみる。

xlview.cmd
@Echo OFF

Set TARGET=%1
Set THISPATH=%0
Set THISFILE=%~n0%~x0
Set XLVIEW=C:\Program Files\Microsoft Office\Office12\xlview.exe

If x%TARGET%==x (
  Echo.
  Echo.Usage: %THISFILE% (file including target filepath or url^)
  Echo.
  Pause
  Exit
)


For /F "usebackq tokens=* eol=" %%i In (`"type %TARGET%"`) Do Set FILENAME=%%i
Echo %FILENAME%

start "" "%XLVIEW%" "%FILENAME%"

今のところ問題ないみたい。

2011年4月5日火曜日

Cygwin で rename コマンド

(2012.01.19)更新

rename
#!/bin/sh

if [ $# -lt 2 ]; then
  echo "USAGE: $0 /変更対象/変更後/ ファイル名展開のパターン文字列"
  exit 0
fi
RE="$1"
shift 1

# ファイル名が - で始まるとき ./ を先頭に挿入
# ファイル名内の ' を '\\\\'' でクォート
#   →sed('\\'') →mv('\'')
# ファイル名をホールドスペースへ保存
# ファイル名を ' でクォート
# パターンスペースとホールドスペースを交換
# ファイル名を正規表現で変換
# 変換したファイル名を ' でクォート
# 変換したファイル名をホールドスペースへ追記
# パターンスペースとホールドスペースを交換
# 改行をタブに変更してから
# xargs で mv へ送る
while [ $# -gt 0 ]; do
 echo "$1";
 shift 1
done | sed -e "
s/^-/.\/-/
s/'/'\\\\''/g
h
s/^/'/
s/$/'/
x
s$RE
s/^/'/
s/$/'/
H
x
s/\n/\t/
" | xargs -L 1 mv -v

(2011.04.05)

rename コマンドを実行したら "bash: rename: command not found"。cygwin.com のパッケージ検索ページでも見つからない。

Cygwin にはどうやら rename コマンドがないらしいので、下記ページを参考に sed ベースで書き換えてみる。

  • 【Linux Tips】 テキストファイルの一括置き換え/ファイル名の一括置き換え: 日々此精進
    → http://murakan.cocolog-nifty.com/blog/2009/11/linux-tips-5aa7.html
/bin/bash
$ /bin/ls -d ファイル名展開のパターン文字列 | sed -e '
s/ /\\ /g
h
s/変更対象/変更後/
x
G
s/\n/\t/
' | xargs -L 1 mv

ファイル名が .txt で終わるファイルの前に今日の日付を追加するなら、

/bin/bash
/bin/ls -d  *\.txt | sed -e "
s/ /\\ /g
h
s/^/$(date +"%y%m%d")-/
x
G
s/\n/\t/
" | xargs -L 1 mv