| Richard's profileRichard Siddaway's BlogPhotosBlogLists | Help |
|
November 05 Creating Temporary filesOne thing I need to do when testing file system scripts is generate a bunch of temporary files for experimenting with. In the past I have just copied in whatever I could find to use as test data. It is possible to easily generate test data of this sort using the New-TempFile function below.
The function takes two arguments – a path and a file size. My default values are given but they can be easily changed to suit you system. After checking that the path exists I generate a random file name using GetRandomFile(). We could use GetTempFileName() but that creates an empty file in the temporary folder which isn’t quite what I want. If the size is zero an empty file is created on the given path. Otherwise if size is supplied e.g. New-TempFile -size 5kb then a number of 128byte lines are written into the file. If larger files are being routinely created increase the size of the string to 512 bytes – or put a test on say 100kb size and use the bigger string in that case. Add-Content is used to write the data into the file. One enhancement is to allow the setting of the file extension. TrackbacksThe trackback URL for this entry is: http://richardsiddaway.spaces.live.com/blog/cns!43CFA46A74CF3E96!2595.trak Weblogs that reference this entry
|
|
|