Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Question about Moving/Renaming Files in VBScript

Posted on 2007-10-10
Medium Priority
Last Modified: 2013-04-20
I have a VBScript coded to pull all TXT files from a specific directory, and move/rename them with a prepended "SD-" in front of the filename.

Here is the current VB code:

Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim strCurrentFolder
strCurrentFolder = "c:\HWM\MachineData"
Dim objFolder
Set objFolder = objFSO.GetFolder(strCurrentFolder)

ListDirectory objFolder

Sub ListDirectory(objFolder)
  Dim objFile
  Dim objSubFolder

  For Each objFile In objFolder.Files
    If UCase(Right(objFile.Path, 3)) = "TXT" Then
        objFSO.MoveFile objFile.Path, "SD-" & objFile.Name
    End If  
End Sub

The problem is, the files are being moved to wherever my script is run from, and I want them moved to a specific path.  I've went round and round, but it seems like when I have the specific destination path right, it breaks the move.

All help appreciated!
Question by:imsysadmin
LVL 93

Accepted Solution

Patrick Matthews earned 200 total points
ID: 20050862
       objFSO.MoveFile objFile.Path, "c:\folder\subfolder\SD-" & objFile.Name

Author Comment

ID: 20050898
Thank you matthew, worked perfect!

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question