1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Windowsバッチファイルの基本と便利な使い方

Last updated at Posted at 2025-02-28

Windowsバッチファイルの基本と便利な使い方

Windowsバッチファイル(.bat)は、Windows環境でコマンドを自動化するためのシンプルなスクリプトです。本記事では、バッチファイルの基本構文と便利な使い方を紹介します。

1. バッチファイルとは?

バッチファイル(Batch file)は、Windowsのコマンドプロンプトで実行できるコマンドをまとめて記述したテキストファイルです。拡張子は .bat または .cmd になります。

2. 基本的な書き方

バッチファイルは、メモ帳などのエディタで作成し、.bat 拡張子で保存するだけで実行できます。

2.1. 簡単なバッチファイルの例

@echo off
echo Hello, Windows Batch!
pause

説明:

@echo off : コマンドの表示を抑制
echo : 文字列を表示
pause : ユーザーのキー入力を待機

3. 便利なバッチ処理

3.1. ファイルのコピー

@echo off
copy C:\source\file.txt D:\backup\
echo ファイルをコピーしました。
pause

3.2. フォルダ内のファイル一覧を取得

@echo off
dir C:\Users > filelist.txt
echo ファイル一覧をfilelist.txtに出力しました。
pause

3.3. 繰り返し処理(forループ)

@echo off
for %%f in (*.txt) do echo %%f
pause

このスクリプトは、カレントフォルダ内の .txt ファイルの名前を一覧表示します。

4. まとめ

Windowsバッチファイルは、簡単な自動化スクリプトを作成するのに便利なツールです。基本的なコマンドを理解し、作業の効率化に活用してみましょう!

1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?