Had a customer that needed a very complex file system for testing a backup application and being able to contrast a file based migration versus a worst case scenerio of a file based tool. I looked at a number of tools and none of them did specifically what I needed to do. The tool should build very deep and wide directories with millions of files. So I wrote the following that creates a huge Directory tree that is X wide and Y deep with Z Files.
It estimates how many files it will create as well as how many directories as well as a rought estimate of time required to complete.
See sample output below;
PS X:\PowerShell\create1billion> .\BuildManyFilesv0.76.ps1
Supply values for the following parameters:
Files: 25
Depth: 4
Width: 3
Mass File Creator starting with following attributes
Files = 25,Depth = 4,Width = 3
Number of Files will Equal 1600
Space needed will equal 6553600 Bytes
At 50 Files/Second ; Time to Completion = 0.444444444444444 Hours
At 50 Files/Second ; Time to Completion = 0.0185185185185185 Days
At 50 Files/Second ; Time to Completion = 5.07356671740233E-05 Years
Start Time = 4/21/2011 1:59:21 PM
See Sample Code Below;
# Test program to create Many on a Drive Letter
# To run this program simply go to the drive letter you want To test against.
# Then type .\createFiles.ps1
#
# Program will create a all the container directoys that is named 1...x.
# Under that directory it will create 1...x subdirectorys deep,
# and x Directorys wide, and each directory will contain the prescribed file count.
# Each file will contain a file named by the time down to the millisecond
# Each file will contain psuedo-random data
param( [parameter(Mandatory=$True)][validaterange(2,1024)][int]
$Files = $(read-host -prompt "Number Of Files per Dir. (2-1024)"),
[parameter(Mandatory=$True)][validaterange(2,100)][int]
$Depth = $(read-host -prompt "Number of Directorys Deep (2-256)"),
[parameter(Mandatory=$True)][validaterange(2,100)][int]
$Width = $(read-host -prompt "Number of Directorys Wide (2-256)"),
[parameter(Mandatory=$True)][validaterange(4096,65536)][int]
$FileSize = $(read-host -prompt "Size of File in Bytes (4096-65536)")
)
function simppow($a, $b)
{ if ($b -eq 0) { return 1 }
else { return ((simppow $a ($b-1)) * $a) }
}
function createdir($dep, $width, $depth, [int]$NumOfFiles, $Filesize)
{ if ($dep -eq '0')
{ $textout = (1..$FILESIZE|% {[char[]](Get-Random -Maximum 300)}) -join ""
1..$NumOfFiles|%{ $filename="{0:MM} Month {0:dd} Day {0:HH} Hour {0:mm} Minute {0:ss} Second {0:FFF} MS.log" -f [datetime]::Now
$TEXTOUT | out-file -filepath $Filename }
write-host "Created"$NumOfFiles" Files dir="$(pwd).Path" : Stamp = "(get-date)
$supress = cd ..
createdir ($dep+1) $width $depth $NumOfFiles $filesize
}
else
{ $name=1
while(test-path $name) { $name++ }
if ($name -gt $width)
{ if ($dep -eq $depth){ return }
$supress = cd ..
createdir ($dep+1) $width $depth $NumOfFiles $filesize
}
else
{ $supress = mkdir $name
$supress = cd $name
createdir ($dep-1) $width $depth $NumOfFiles $filesize
}
}
}
# Main Body
write-host "Mass File Creator starting with following attributes "
write-host "Files = $Files,Depth = $Depth,Width = $Width,FileSize=$FileSize Bytes"
$NumberOfFiles=(simppow $Depth $Width)*$Files
Write-host "Number of Files will Equal $NumberOfFiles"
Write-host "Space needed will equal "($NumberOfFiles*$Filesize)" Bytes"
if (($numberoffiles/3600/24/365) -gt 1)
{ Write-host "At 50 Files/Second ; Time to Completion ="($numberoffiles/3600/24/365)" Years"
}
elseif (($numberoffiles/3600/24) -gt 1)
{ Write-host "At 50 Files/Second ; Time to Completion ="($numberoffiles/3600/24)"Days"
}
else
{ Write-host "At 50 Files/Second ; Time to Completion ="($numberoffiles/3600)" Hours"
}
write-host "Start Time = "(get-date)
createdir $depth $width $depth $Files $FileSize
write-host "End Time = "(get-date)