Error writing file name which contain both English and non-English name RRS feed

  • Question

  • Hello

    I have this simple vbscript code which suppose to write all file names in some directory to a text file

    Dim FSO
    Dim FileDirectory
    FileDirectory = "C:\temp"
    Dim FileList
    FileList = "list.txt"
    Dim Fname
    Set FSO = CreateObject("Scripting.FileSystemObject")
    set FileDirectory = FSO.GetFolder(FileDirectory)
    Set objFile = FSO.CreateTextFile(FileDirectory & "\" & FileList ,True)
    	for each file in FileDirectory.files
    	Fname =
    	objFile.Write( ChrW(34) &  Fname  & ChrW(34) & vbCrLf)
    	objFile.Write( ChrW(34) & FileDirectory & "\" &  Fname  & ChrW(34) & vbCrLf)

    Everything goes fine while file names are in English but when some file name is non English or both  English with non English name (right to left languages) an error raised, so how to deal with this writing issue without changing the file name ?

    thanks in advance

    Tuesday, February 17, 2015 1:37 AM


All replies

  • This might work a bit better:

    strDirectory = "C:\temp"
    strFileList = "c:\temp\list.txt"
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set objFile = fso.CreateTextFile(strFileList,True)
    Set folder = fso.GetFolder(strDirectory)
    For each file in folder.files
    	objFile.WriteLine file.Path


    • Edited by jrv Tuesday, February 17, 2015 2:21 AM
    Tuesday, February 17, 2015 2:20 AM
  • Thanks jrv for replying

    I tested you code but it didn't worked for me (works fine for English file names but doesn't work with right to left language )

    Tuesday, February 17, 2015 1:29 PM
  • VBScript does not support Unicode or R2L.


    • Marked as answer by zampoot Thursday, February 19, 2015 3:31 AM
    Tuesday, February 17, 2015 7:11 PM