Sign in to follow this  
Followers 0
XnT

Extended ANSI Characters

7 posts in this topic

Hi, searched the forum and can't find solution.

Problem is I am reading the contents of a directory with the ComSpec + dir command. One file has the extended ansi character '«' in its filename. When output to the screen, the Dir command can display it ok. But when i redirect the output to a file (using '> dir.txt') the character is written as '®'. This effectively changes the filename and it can no longer be referenced back.

here's my code.

If Not FileExists(@ScriptDir & '\testfolder\File with « character.txt') Then 
    $File = FileOpen(@ScriptDir & '\testfolder\File with « character.txt',10)
    FileWrite($File,'Some content')
    FileClose($File)
EndIf
RunWait(@ComSpec & ' /c dir /b /s "' & @ScriptDir & '\testfolder\*.*" > dir.txt',"",@SW_HIDE)
$Dir = FileRead("dir.txt")
$Dir = StringStripWS($Dir,3)
$aDir = StringSplit(StringStripCR($Dir),@LF)
For $i = 1 to $aDir[0]
    If FileExists($aDir[$i]) Then
        MsgBox(0,"File exists",$aDir[$i])
    Else
        MsgBox(0,"File does not exist",$aDir[$i])
    EndIf
Next

I would really appreciate any help. Thanks very much.

Share this post


Link to post
Share on other sites



Maybe _FileListtoArray is a solution. It list files, folders or both into an array to work with. Therefore the problem with ansi - ascii shoudn't appear.

;-))

Stefan

Share this post


Link to post
Share on other sites

Maybe _FileListtoArray is a solution. It list files, folders or both into an array to work with. Therefore the problem with ansi - ascii shoudn't appear.

;-))

Stefan

The problem from _FileListToArray is, that only file and folders from the current directory are displayed. So you have build a loop to find out the directories in the array, then list files an folders from the array directory, find out the directories and so. It seem to be not practible, sry. ;-((

Maybe StdoutRead is a possibilty to work with.

Share this post


Link to post
Share on other sites

Recursion is very common, it's been discussed before and there are examples. 99ojo, please edit your posts instead of posting new posts.

Share this post


Link to post
Share on other sites

The problem from _FileListToArray is, that only file and folders from the current directory are displayed. So you have build a loop to find out the directories in the array, then list files an folders from the array directory, find out the directories and so. It seem to be not practible, sry. ;-((

Maybe StdoutRead is a possibilty to work with.

I thought that piece of crap had been fixed a long time ago. You can use it with the added function as shown below. Randallc also has a different version of _FileListToArray() posted in the Example Scripts forum.

;
#include <file.au3>
#include <array.au3>;; Only required for _ArrayDisplay() and _ArraySort if the comment from that line in the func is removed
Global $aFiles, $sFiles = ""
$aFldr = _FldrListToArray(@MyDocumentsDir)
For $i = 1 To Ubound($aFldr) -1
  $aTemp = _FileListToArray($aFldr[$i])
  For $j = 1 To Ubound($aTemp) -1
    $sFiles &= $aTemp[$j] & "|"
  Next
Next
$aFiles = StringSplit(StringTrimRight($sFiles, 1), "|")

_ArrayDisplay($aFiles, "Finished")

;===============================================================================
; Function Name:    _FldrListToArray()
; Description:    Recursivly find the folders in a given path
; Syntax:          _FldrListToArray($szRoot, $nFlag = 1 )
; Parameter(s):  $szRoot - The base folder
;                  $iRecurs - If 1 (default) search is recursive
; Requirements:
; Return Value(s):  Success - An array of the folders with paths
;                  Failure - None
; Author(s):        GEOSoft
; Notes:
;===============================================================================

Func _FldrListToArray($szRoot, $iRecurs = 1 )
   If StringRight($szRoot, 1) <> '\' Then $szRoot &= '\'
   Local $szReturn = '',  $szBuffer = '', $szPathlist = '*', $oRoot = $szRoot & '*'
      $Hfile = FileFindFirstFile ($szRoot &'*')
      If $Hfile >= 0 Then
         $szBuffer = FileFindNextFile ($Hfile)
         While NOT @Error
            If Not StringInStr($szBuffer, '.') Then $szPathlist &= $szRoot & $szBuffer & "\*"
            $szBuffer = FileFindNextFile ($Hfile)
         Wend
         FileClose ($Hfile)
      EndIf
      $szReturn = $szPathList

   If $iRecurs = 1 Then
      $szPathList = StringTrimLeft($szPathlist, 1)
      $szRoot = StringLeft($szPathList, StringInStr($szPathlist, '*') -1)
      While 1
         $hFile = FileFindFirstFile ($szRoot & '*')
         If $hFile >= 0 Then
            $szBuffer = FileFindNextFile ($Hfile)
         While NOT @Error
            If Not StringInStr($szBuffer, '.') Then
               $szPathlist &= $szRoot & $szBuffer & "\*"
               $szReturn &= $szRoot & $szBuffer & "\*"
            EndIf
            $szBuffer = FileFindNextFile ($Hfile)
         Wend
         FileClose($hFile)
         $szPathList = StringReplace($szPathList, $szRoot, '')
         EndIf
         If $szPathList == '*' Then ExitLoop
         $szPathlist = StringTrimLeft ($szPathlist, 1)
         $szRoot = StringLeft ($szPathlist, StringInStr ($szPathlist, "*") - 1) & "\"
         $szPathlist = StringTrimLeft ($szPathlist, StringInStr ($szPathlist, "*") - 1)
      Wend
   EndIf
   If StringLeft($szReturn, 1) = '*' Then $szReturn = StringTrimLeft($szReturn, 1)
   $szReturn = StringReplace($szReturn, '\\', '\')
   If StringRight($szReturn, 1) = '*' Then $szReturn = StringTrimRight($szReturn,1)
   $szReturn = StringSplit($oRoot & $szReturn,'*')
   If $szReturn = '*' or $szReturn = '' Then Return 0
  ; _ArraySort($szReturn);; << uncomment and #include <array.au3> to return a sorted array
   Return $szReturn
EndFunc  ;<==> _FldrListToArray()
;

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Thanks guys, I did think of using this function but I assumed that it would be slower reading from large directories than the built-in windows command. :mellow:

Really appreciate the help.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0