DaveWentzel.com            All Things Data

CreateFileNamesBasedOnDate


Seems like I do this all the time to import/extract data to/from text files.  I usually use DOS or VBscript.  Here's an example using PS:

 

Function GetFileName([ref]$filename)

{

   $invalidChars = [io.path]::GetInvalidFileNamechars()

   $dt = get-date -format s

   $filename.value = ($dt.ToString() -replace "[$invalidchars]","-" + ".txt"

}

 

$filename = $null

GetFileName([ref]$filename)

new-item -path <whatever> -name $filename -itemtype file

 

 

Add new comment