15. VbScript | Copy, Move, Rename Files & Folder

Video Walkthrough:

Try using the code in order to make sure you understand.

So this tutorial is about copying, moving, and renaming files and folders using VbScript.

Below is the format of the script to copy and to move the files and folders. Note that the root command is CreateObject(“Scripting.FileSystemObject”):

You put the current address of the file/folder where it says “LOCATION”, and put the new address where you want to move or copy the file/folder where it says “NEW LOCATION”.

Copy File into Folder

For example, let’s say I want to copy my picture on the desktop to a new folder on the desktop

Cat into Folder

The address of either folder or pic can be found by right clicking either folder or picture and selecting properties. Find the location descriptor.

b2 b3

Insert the locations into the code:

Note that the picture ends with .jpg, and the ending location must end with a backslash \

Move Folder into Folder

Let’s say I want to move a folder into another folder.


Both are on the desktop “C:\Users\rock\Desktop”. So all you have to do is add the folder names.

Again, the ending location must end with a backslash \



Rename File or Folder

Video Walkthrough:

Renaming a file or folder would use the move command, since the copy command causes there to be duplicates.

To rename a file, let the NEW LOCATION be a file with a different name.

To rename a folder, don’t add the backslash \ at the end of the NEW LOCATION and have a different name for the folder

Move or Copy Multiple Files into Folder

If you only want to move the all the files, but not the folder use *.* or *

If you only want to move all the files of a specific type use * plus the extension (i.e. *.txt or *.jpg)

If you only want to move all the files of a specific name, regardless of type, use * after the filename and period (ie. catpic.* or file.*)

Example: Check Before Copy/Move

To check if a folder or file exists before moving or copying a file/folder:

Remember that the placement of the backslash \ affects how the VbScript reads & runs the code.

4 thoughts to “15. VbScript | Copy, Move, Rename Files & Folder”

  1. Is it possible to do multiple commands?

    fso.MoveFile “C:\Users\rock\Desktop\TestFolder\BigEyeCat.*”, “C:\Users\rock\Desktop\TestFolder1\”
    fso.MoveFile “C:\Users\rock\Desktop\TestFolder2\BigEyeCat2.*”, “C:\Users\rock\Desktop\TestFolder2\”
    fso.MoveFile “C:\Users\rock\Desktop\TestFolder\BigEyeCat3.*”, “C:\Users\rock\Desktop\TestFolder3\”

  2. I am using the method above mentioned to copy files to a USB card.
    After issuing this command I then issue a command to eject the USB card.
    The eject fails because the USB card is in use.

    Is there a way to detect when the copy is completed?


  3. Hello, i need to move specified file Statistic-C1.txt but only when the file is older then 14 days. now i have this but when i wanna put file path into the code it shows me error.
    Dim fso, f, f1, fc, strComments, strScanDir

    strDir = “d:\test_bat\”
    strDays = 14
    Arc_Folder = “d:\presun\”

    Set fso = CreateObject(“Scripting.FileSystemObject”)
    Set f = fso.GetFolder(strDir)
    Set fc = f.Files
    For Each f1 in fc
    If DateDiff(“d”, f1.DateCreated,Now) > strDays Then
    fso.movefile F1, arc_folder
    End If
    Done = msgbox(“Záloha dokončena”,vbokonly)

What's Your Opinion?