Display: Cloud | List
Most Popular Tags
Results (5 total) All > powershell (x) > system.io.path (x)
Sample Using PowerShell (FileInfo Class (System.IO))
<#.SYNOPSIS This script creates then copies a file using System.IO.Fileinfo.CopyTo().DESCRIPTION This script first creates a temporary file, then copies it to another file then deletes the second file..NOTES File Name : Create-TempFile.ps1 Author : Thomas Lee - tfl@psp.co.uk Requires : PowerShell V2.LINK This script posted to: http://www.pshscripts.blogspot.com
Last modified by Thomas Lee on 10/6/2009 8:21:11 AM
Sample Using PowerShell (Path.GetExtension Method (System.IO))
# Get-Extension.ps1 # Sample using PowerShell # Thomas Lee - tfl@psp.co.uk #Set values $fileName="C:\mydir.old\myfile.ext"$path="C:\mydir.old\"# Get filename extension$extension= [System.IO.Path]::GetExtension($fileName)"GetExtension('{0}') returns '{1}'"-f$fileName, $extension# Get Path Extension (hint: there is none!)$extension= [System.IO.Path]::GetExtension($path)"GetExtensio
Last modified by Thomas Lee on 11/11/2008 7:58:07 PM
GetTempFileName Method with Powershell (Path.GetTempFileName Method (System.IO))
# get-GetTempFileName.ps1# Creates a uniquely named, zero-byte file in the temp dir# Thomas Lee - tfl@psp.co.uk # Get file name (and create the file!):$fn1 = [system.io.path]::GetTempFileName()# Display Results"File name returned: $fn1"ls $fn1# delete the fileDel $fn1 This script produces the following output:PSH [C:\foo]: .\get-tempfilename.ps1File name returned: C:\Documents and Settings\tfl\Lo
Last modified by Thomas Lee on 7/13/2008 6:53:17 PM
GetRandomFileName with PowerShell (Path.GetRandomFileName Method (System.IO))
# get-randomfilename.ps1# Gets a random filename# Thomas Lee - tfl@psp.co.uk # Get two random file names:$fn1 = [system.io.path]::getrandomfilename()$fn2 = [system.io.path]::getrandomfilename()# Display Results"Random file name 1: {0}" -f $fn1"Random file name 2: {0}" -f $fn2A This script produces the following output (NB: file names produced varies each time the script is run!) PSH [C:\foo]:
Last modified by Patrick McDonald on 8/6/2008 2:38:15 PM
ChangeExtension using PowerShell (Path.ChangeExtension Method (System.IO))
# change-extensions.ps1# changes extensions using PowerShell# Thomas Lee - tfl@psp.co.uk# setup file names$goodFileName = "C:\mydir\myfile.com.extension"$badFileName = "C:\mydir\"# change file name$result = [System.IO.Path]::ChangeExtension($goodFileName, ".old")"ChangeExtension({0},'.old') returns '{1}'" -f $goodFileName, $result$result = [System.IO.Path]::ChangeExtension($goodFileName, "")"Chang
Last modified by Thomas Lee on 7/5/2008 9:43:10 PM
Page view tracker