| Richard's profileRichard Siddaway's BlogPhotosBlogLists | Help |
|
November 11 Extension for temporary filesWhen I did the post on creating temporary files http://msmvps.com/blogs/richardsiddaway/archive/2009/11/05/creating-temporary-files.aspx I said I’d modify it so the file would be created with a given extension.
It just involves adding another parameter $ext with a default empty string value. If we give an extension New-TempFile -size 2kb -ext "txt" -path "c:\test\test2" Then we test to see if it starts with a . and remove it. We then replace the extension of the randomly generated filename using a regular expression match on the extension [ the regex is translated as 3 characters following a . The \ is an escape character so . is read literally rather than as a wildcard] Everything else is the same. One other thing I might do is change the way data is put into the files. For larger files its slow so I might do something different there. This is one of great features of working with PowerShell like this – I can get a working script quickly and then refine it over time as I get chance to think about it. Because I can work interactively at the prompt I can quickly test ideas before changing the script. TrackbacksThe trackback URL for this entry is: http://richardsiddaway.spaces.live.com/blog/cns!43CFA46A74CF3E96!2604.trak Weblogs that reference this entry
|
|
|