web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

IM - VB script to rename source file

(0) ShareShare
ReportReport
Posted on by 1,069

I am trying to use the "Renaming a Source File that Uses Today's Date in its Name" from the IM Script Library but am running into a syntax problem.  I'm pretty sure it is because I have a space in the file name, but not sure how to correct.  The error occurs on Line 12:

' Added by the IM Script Library
' Category: General Purpose Scripts
' Script Type: After Query Script

'Set the Path & Filename of the Source file and the Destination
'file. In this example, the destination file is named "Done 20000829",
'where "20000829" represents the system date, in the following
'format: yyyymmdd.

sSourceFile = "\\2k3-dfsql\Payroll\ABC AP_Upload.txt"

sDestinationFile = "\\2k3-dfsql\Payroll\Backup Garnishments\ABC AP_Upload & Year(Date) & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2) & ".txt"

'Create a File System Object

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

'Copy and rename the file
'The "True" parameter indicates that if the file already exists
'in the destination, then it will be overwritten

Call pFSO.CopyFile(sSourceFile, sDestinationFile, True)

Thank you for your help!

*This post is locked for comments

I have the same question (0)
  • WindyCityGP Profile Picture
    1,069 on at

    Figured it out.

  • Suggested answer
    Ian Grieve Profile Picture
    22,784 on at

    I'm figuring it was the missing double quote from after ABC AP_Upload?

  • Verified answer
    WindyCityGP Profile Picture
    1,069 on at

    Correct, Ian.  Once I changed it to the following, it worked fine:

    sSourceFile = "\\2k3-dfsql\Payroll\ABC AP_Upload.txt"

    sDestinationFile = "\\2k3-dfsql\Payroll\Backup Garnishments\ABC AP_Upload" & Year(Date) & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2) & ".txt"

    'Create a File System Object

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

    'Copy and rename the file
    'The "True" parameter indicates that if the file already exists
    'in the destination, then it will be overwritten

    Call pFSO.CopyFile(sSourceFile, sDestinationFile, True)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics GP (Archived)

#1
mtabor Profile Picture

mtabor 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans