LoginSignup
3
2

More than 3 years have passed since last update.

フォルダ内のフォルダ/ファイル名を取得

Last updated at Posted at 2017-02-28

はじめに

Windowsのコマンドラインで、フォルダの中にある全フォルダ/ファイルの名前を取得する。
ただし、サブフォルダ以下の名前と拡張子は取得しない。

例えば、C:\Users\USER\Downloadsにある全ファイルを取得し、C:\Users\USER\Downloadsのresult.txtに書き出す。

実行前

取得したいフォルダ
C:\Users\USER\Downloads\apple.txt
                       \banana.pdf
                       \grape\muscat.csv

コマンドプロンプトを開き、以下のコードを実行。

for /f "delims=" %i in ('dir /b 出力したいファイル群が入ったフォルダの場所') do @(echo %~ni)>>出力したい場所\テキスト名.txt

C:\Users\USER>

C:\Users\USER>for /f "delims=" %i in ('dir /b C:\Users\USER\Downloads') do @(echo %~ni)>>C:\Users\USER\Downloads\result.txt

実行後

result.txt
apple
banana
grape

その他

・すべて
  >dir /b "パス"
・ファイル名のみ 
  >dir /b/a-d "パス"
・フォルダ名のみ
  >dir /b/a-a "パス"

参考

コマンドプロンプトの使い方

3
2
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
3
2