XnT Posted October 30, 2008 Posted October 30, 2008 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.
dbzfanatic Posted October 30, 2008 Posted October 30, 2008 Why not try Chrw() and AscW() to change it and ensure that you get the proper value? Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote]
99ojo Posted October 30, 2008 Posted October 30, 2008 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
99ojo Posted October 30, 2008 Posted October 30, 2008 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.;-))StefanThe 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.
dbzfanatic Posted October 30, 2008 Posted October 30, 2008 Recursion is very common, it's been discussed before and there are examples. 99ojo, please edit your posts instead of posting new posts. Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote]
GEOSoft Posted October 30, 2008 Posted October 30, 2008 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. expandcollapse popup; #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!"
XnT Posted October 31, 2008 Author Posted October 31, 2008 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. Really appreciate the help.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now