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

VBS Windowsでファイル一覧を取得する

Posted at

Windowsでファイルの一覧を取得したい場合のスクリプト
カレントディレクトリのリストを読み取り、テキストファイルに保存します。

ファイル一覧取得.vbs
'ファイル一覧を取得して、テキストに保存します。

Option Explicit
 
Dim objFileSys
Dim objFolder
Dim objFile
Dim objOutputTextStream
Dim fso

'カレントディレクトリ取得
Set fso= createObject("Scripting.FileSystemObject")

'ファイルシステムを扱うオブジェクトを作成
Set objFileSys = CreateObject("Scripting.FileSystemObject")
 
'ログ出力用 TextStream オブジェクトを作成
'第2引数は 1 :読み取り、2 :上書き、3 :追記。
Set objOutputTextStream = objFileSys.OpenTextFile("ファイル一覧.txt", 2, True)

'フォルダのオブジェクトを取得
Set objFolder = objFileSys.GetFolder(fso.getParentFolderName(WScript.ScriptFullName))

'FolderオブジェクトのFilesプロパティからFileオブジェクトを取得
For Each objFile In objFolder.Files
    'ファイル名を取得し、ログファイルに出力
    objOutputTextStream.WriteLine objFile.Name
Next
 
'TextStream は Close を忘れずに
objOutputTextStream.Close

Set objOutputTextStream = Nothing
Set objFolder  = Nothing
Set objFileSys = Nothing 

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