LoginSignup
1
1

More than 3 years have passed since last update.

bat_ショートカット先の実体コピー

Last updated at Posted at 2019-08-16

1.概要

実行ディレクトリ内に存在する.lnkのリンク先の実体を
実行ディレクトリにコピーするバッチ。
・リンク先がディレクトリならディレクトリごとコピーする。
・リンク先は実行ディレクトリはCドライブとしている(変更可能)。

2.ソースコード

@echo off

rem ショートカットの実体をコピーするバッチ
::実行ディレクトリ内のリンクファイルの実体を
::実行ディレクトリにコピーします。

::lnkファイルの実体パスをtemp.txtに出力
type *.lnk|find "C:\"|find /v "/">temp.txt

::temp.txtのパスを読み出し、実行ディレクトリにコピー
:: ※フォルダの場合…フォルダごとコピーする
for /f "delims=" %%A in (temp.txt) do (
   if exist %%A\ (
      echo D | xcopy "%%A" "%~dp0\%%~nxA" /Y
   ) else (
      copy "%%A" "%~dp0" /Y
   )
)
::不要になったtemp.txtを削除
if exist "temp.txt" del temp.txt
pause

3.出力結果

(略)
適当にショートカットを作って実行してみてください。

4.出典

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1