VBScript Basics, Part 15 | Copy – Move – Rename – Files & Folders
VBScripting (.vbs) Basic tutorial on how to copy, move, and rename files and folders. Use an asterisk to copy or move multiple files and folders at a time. Also how to make sure and check if they exist before doing so.
Code Example:
______________________________________________________
Option Explicit
Dim fso
Set fso = CreateObject(“Scripting.FileSystemObject”)
If fso.FileExists(“C:UsersJeremyDesktopsinking.jpg”) then
fso.CopyFile “C:UsersJeremyDesktopsinking.jpg” , “C:UsersJeremyDownloadsTest”
Else
wscript.echo “doesn’t exist”
End If
______________________________________________________
Know the Basics:
——————————————————————————————
Set x = CreateObject(“Scripting.FileSystemObject”)
x.CopyFile “LOCATION” , “NEW LOCATION”
x.CopyFolder “LOCATION” , “NEW LOCATION”
——————————————————————————————
x.MoveFile “LOCATION” , “NEW LOCATION”
x.MoveFolder “LOCATION” , “NEW LOCATION”
——————————————————————————————
RENAME: works with both copy and move command.
x.MoveFile “LOCATION” , “NEW or same LOCATIONnewname.ext”
x.MoveFolder “LOCATION” , “NEW or same LOCATIONnewname”
——————————————————————————————
ASTERISK: when moving/copying files.
Any Name | *.extension
Any Extension | name.*
Any/All Files | *.*
——————————————————————————————