- <#
- .SYNOPSIS
- This script displays the usage of the Exists and the
- copy methods of System.IP.File
- .DESCRIPTION
- This script sets up two file names, then checks to see if
- the sorucefile exists. if so, it's copied to a new file.
- .NOTES
- File Name : copy-file.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2 CTP3
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN Sample posted at:
- http://msdn.microsoft.com/en-us/library/system.io.file.exists.aspx
- .EXAMPLE
- PSH [C:\foo]: .\Copy-File.PS1'
- Source File (c:\foo\Test.txt) copied to (c:\foo\Test2.txt)
- #>
- ##
- # start of script
- ##
- # Setup source and destination files
- $SourceFile = "c:\foo\Test.txt";
- $NewFile = "c:\foo\Test2.txt";
- # Now - check to see if $Sourcefile exists, and if so,
- # copy it to $newfile
- if ([System.IO.File]::Exists($SourceFile)) {
- [System.IO.File]::Copy($SourceFile, $NewFile)
- "Source File ($SourceFile) copied to ($newFile)"
- }
- else {
- "Source file ($Sourcefile) does not exist."
- }
- # End of script
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Thursday, 9 July 2009
Copy-File.ps1
Labels:
powershell,
PowerShell scripts,
System.Io.File
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment