Wednesday, April 04, 2012

VBScript to copy file and Powershell Script to copy file

VBScript to copy file:

dim filesys, oShell
Set filesys = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")
sup = oShell.ExpandEnvironmentStrings ("%APPDATA%")
des = oShell.ExpandEnvironmentStrings ("%ProgramFiles(x86)%")
destfile= sup & "\AR System\HOME\AR"
sourcefile= des & "\AR System\User\AR"
If filesys.FileExists(sourcefile) Then
   filesys.CopyFile sourcefile, destfile
End If

Powershell Script to copy file:

$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." 

No comments: