LoginSignup
2
3

More than 5 years have passed since last update.

Windows 容量指定ダミーファイルを複数作成するシェルスクリプト

Last updated at Posted at 2018-10-22

windowsで負荷テストを行う際に使えるコマンドやシェルスクリプトをご紹介します。

環境

以下の環境での動作は確認しています。
Windows7 Enterprise × Powershell 5.0
Windows10 Pro × Powershell 5.1

Windowsでダミーファイル作成コマンド

構文

> fsutil file createnew {ファイル名} {ファイル容量(バイト)}

以下は、10バイトのファイルを作成する場合の例です。

> fsutil file createnew testfile 10

容量を指定した複数のダミーファイルを作成

複数のファイルを作成する場合には、シェルスクリプトを使うと便利です。
下記をコピーしてpowershellで実行すると、指定した容量の複数のダミーファイルを作成できます。

createFiles.ps1
Param(
    [Parameter(Mandatory=$true)][string]$path,
    [Parameter(Mandatory=$true)][int]$count,
    [Parameter(Mandatory=$true)][int]$size
)
# ファイル作成または上書き
for ($i = 0; $i -lt $count; $i++) {
    $filePath = $path + "\testFile" + $i
    if (Test-Path $filePath) {
        Remove-Item $filePath;
    }
    fsutil file createnew $filePath $size
}

実行コマンド

> .\createFiles.ps1 {フォルダパス} {数量} {容量}

例)C:\testに100バイトのファイルを10個作成する場合

> .\createFiles.ps1 C:\test 10 100
2
3
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
2
3