locked
VBA - File System Object - Open file having special characters on the name RRS feed

  • Question

  • Hi,

    I am trying to write a VBS script file that's called in a cmd file for the following task.

    I want to find the last modified date for all files listed in a text file (having file names with complete path) and I am using FileSystemObject for this. It's working fine for all files except for those file having special characters on their names. For example, file having the name as Exchange Rate Reportò.TXT is not working since it got the character ò in it.

    Here's the script.

    FileName = oArgs(0)

    Dim fso, file, txtstream
    Set fso = CreateObject("Scripting.FileSystemObject")
    Dim f
    Set f = fso.GetFile(FileName)
    dtmDate = f.DateLastModified
    intAge = DateDiff("d", dtmDate, Date)

    Is there a work around for this? Anyway to convert the string to other Charset?

    Appreciate your help.

    Thanks in advance.


    soori

    Wednesday, August 7, 2013 2:16 AM

All replies

  • Hi Soori,

    I failed to reproduce your issue on my lab machines (Windows 8 and Windows 7).

    Below is my code:

    Dim fso, f
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFile("C:\Drafts\Exchange Rate Reportò.txt")
    MsgBox "Last: " & f.DateLastModified

    Could you tell me which version of Windows you are currently using?


    Jeffrey Chen
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Thursday, August 8, 2013 6:42 AM
  • Hi Jeff,

    Thanks for your help. I am using Win 7 Professional SP 1.

    I am using a VBS file having this code running on the command line which is throwing this issue.


    soori

    Thursday, August 8, 2013 2:04 PM
  • Hi Jeff,

    To further add I am not using hardcoded file name as following. It comes from a variable that's read from a input file having the complete path.

    Set f = fso.GetFile("C:\Drafts\Exchange Rate Reportò.txt")

    ----------------------------------------------

    How to reproduce the issue?

    1.Create a folder called "Drafts" under c:\

    2.Unzip all contents Try_Code.zip to c:\Drafts

    3.Open command line and go to c:\Drafts

    4.Run the batch file Run_Try.bat

    ----------------------------------------------

    Can you tell me how to send you Try_Code.zip as attachment.

    Thanks again


    soori

    Thursday, August 8, 2013 2:27 PM
  • Hi Soori,

    You can share your files with me through SkyDrive.


    Jeffrey Chen
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, August 9, 2013 1:40 AM