Sign in to follow this  
Followers 0
PhoenixXL

MayBe A Bug Or Maybe Windows Problem

5 posts in this topic

#1 ·  Posted (edited)

Hey Every1!!!!!!

I have made a Func to get all the files in the Directory Mentioned , The Func even checks the Sub-Directory for the Files....................

I am Having Windows 7 32 Bit...........

I know that i can get if it is a Directory using @extended Macro

But ANyways i tried my own way...........

So If i declare the Variable $RealFile as Local , Everything Just Works Awesome just the value of the Variable Resets upon calling the Variable again

Therefore I declared the Variable as Global ........ Here the Problem Izzzzzzz

Whenever I declare the Var as GLobal .............and run it a message comes up saying 'Autoit v3 Script has stopped working'

Thats It the Script Exits..............

I'm Just not getting It Why the Hell isnt it working.........

Here is a image of the error i get 'IMAGE'

The Code is just The Following

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=X.exe
#AutoIt3Wrapper_Compression=4
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
Opt('TrayIconDebug',1)
Global $NumberOfFiles=1,$x=FileSelectFolder('Heya',''),$RealFile[$NumberOfFiles]
Global $eXt='*.mp3'
Global $glo=_ListFiles_SubDirectory($x,$eXt)
For $i=1 To UBound($glo)-1
FileWriteLine('Abhishek.txt',$glo[$i])
Next

Func _ListFiles_SubDirectory($folder,$Pattern='*.*',$SubFolder=1)
Dim $Search

_CheckSlash($folder)
$Search=FileFindFirstFile($folder&'*.*')
If @error Then ConsoleWrite($folder&" Doesn't Contain Any Files"&@CRLF)
#cs
  Checking For All The Files So That It can
  Be Figured Out ,If Not Even A Single File Of The Mathcing Pattern Is Present
#ce
While $search<>-1
  $RealFile[0]=FileFindNextFile($Search)
  If @error Then ExitLoop
  If IsDirectory($folder&$RealFile[0]) Then
   ReDim $RealFile[$NumberOfFiles+1]
   Local $z=$NumberOfFiles
   $RealFile[$NumberOfFiles]=_ListFiles_SubDirectory($folder&$RealFile[0],$Pattern)
   ConsoleWrite('Listed: '&$folder&$RealFile[$x]&@CRLF)
   $NumberOfFiles+=1
  EndIf
WEnd
FileClose($search)
#cs
  The Part Of The Func Which Does The Main Role Is Just The Following
#ce
If IsArray($Pattern) Then
  For $x In $Pattern
   $Search=FileFindFirstFile($folder&$x)
   While $search<>-1
    ReDim $RealFile[$NumberOfFiles+1]
    $RealFile[$NumberOfFiles]=FileFindNextFile($Search)
    If @error Then
     ExitLoop
    EndIf
    ConsoleWrite('Found: '&$RealFile[$NumberOfFiles]&@CRLF)
    $NumberOfFiles+=1
   WEnd
  Next
Else
  $Search=FileFindFirstFile($folder&$Pattern)
  While $search<>-1
   ReDim $RealFile[$NumberOfFiles+1]
   $RealFile[$NumberOfFiles]=FileFindNextFile($Search)
   If @error Then
    ExitLoop
   EndIf
   ConsoleWrite('Found: '&$folder&$RealFile[$NumberOfFiles]&@CRLF)
   $NumberOfFiles+=1
  WEnd
EndIf
FileClose($search)
Return $RealFile
EndFunc
Func IsDirectory($folder)
If Not FileExists($folder) Then Return -1
Local $Directory=StringInStr(FileGetAttrib($folder),'D',2)
If $Directory<>0 Then Return 1
Return 0
EndFunc
Func _checkslash(ByRef $2check)
If StringRight($2check,1)<>"" Then $2check&=""
Return 1
EndFunc

If any1 here knows the possible solution of the Problem

Plz Reply to me

Thnx In Advance

Regards

PhoenixXL

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites



Your code:

If not IsDeclared('RealFile') Then
Dim $RealFile[NumberOfFiles]
EndIf

is checking to see if the variable exists and if not, create it. You should already know that's it's not declared and IsDeclared wasn't really meant to be used in this manner. Just create it when you start your script and ReDim as needed. I haven't gone through all your code but that jumped out at me immediately.

Also, for what you're trying to do, lots of people have already done before. Just search forums for 'recursive' and you'll get a bunch of helpful hits...unless you're doing this just to learn?

Share this post


Link to post
Share on other sites

Hey MrMitchell You r Actually not getting it!!!!

When Declaring $RealFile as Global Autoit is Crashing............

Try out this Code <Also edited the code in the Original Post>

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=X.exe
#AutoIt3Wrapper_Compression=4
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
Opt('TrayIconDebug',1)
Global $NumberOfFiles=1,$x=FileSelectFolder('Heya',''),$RealFile[$NumberOfFiles]
Global $eXt='*.mp3'
Global $glo=_ListFiles_SubDirectory($x,$eXt)
For $i=1 To UBound($glo)-1
FileWriteLine('Abhishek.txt',$glo[$i])
Next

Func _ListFiles_SubDirectory($folder,$Pattern='*.*',$SubFolder=1)
Dim $Search

_CheckSlash($folder)
$Search=FileFindFirstFile($folder&'*.*')
If @error Then ConsoleWrite($folder&" Doesn't Contain Any Files"&@CRLF)
#cs
  Checking For All The Files So That It can
  Be Figured Out ,If Not Even A Single File Of The Mathcing Pattern Is Present
#ce
While $search<>-1
  $RealFile[0]=FileFindNextFile($Search)
  If @error Then ExitLoop
  If IsDirectory($folder&$RealFile[0]) Then
   ReDim $RealFile[$NumberOfFiles+1]
   Local $z=$NumberOfFiles
   $RealFile[$NumberOfFiles]=_ListFiles_SubDirectory($folder&$RealFile[0],$Pattern)
   ConsoleWrite('Listed: '&$folder&$RealFile[$x]&@CRLF)
   $NumberOfFiles+=1
  EndIf
WEnd
FileClose($search)
#cs
  The Part Of The Func Which Does The Main Role Is Just The Following
#ce
If IsArray($Pattern) Then
  For $x In $Pattern
   $Search=FileFindFirstFile($folder&$x)
   While $search<>-1
    ReDim $RealFile[$NumberOfFiles+1]
    $RealFile[$NumberOfFiles]=FileFindNextFile($Search)
    If @error Then
     ExitLoop
    EndIf
    ConsoleWrite('Found: '&$RealFile[$NumberOfFiles]&@CRLF)
    $NumberOfFiles+=1
   WEnd
  Next
Else
  $Search=FileFindFirstFile($folder&$Pattern)
  While $search<>-1
   ReDim $RealFile[$NumberOfFiles+1]
   $RealFile[$NumberOfFiles]=FileFindNextFile($Search)
   If @error Then
    ExitLoop
   EndIf
   ConsoleWrite('Found: '&$folder&$RealFile[$NumberOfFiles]&@CRLF)
   $NumberOfFiles+=1
  WEnd
EndIf
FileClose($search)
Return $RealFile
EndFunc
Func IsDirectory($folder)
If Not FileExists($folder) Then Return -1
Local $Directory=StringInStr(FileGetAttrib($folder),'D',2)
If $Directory<>0 Then Return 1
Return 0
EndFunc
Func _checkslash(ByRef $2check)
If StringRight($2check,1)<>"" Then $2check&=""
Return 1
EndFunc

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

PhoenixXL,

Your script does not crash for me - although it does fail with an "Array variable has incorrect number of subscripts or subscript dimension range exceeded" error. :)

I have not really tried to debug the script as I hate recursive loops - they are nasty little buggers at the best of times and you have far too many of them in that script. I find it much better to use an iterative approach as explained in the Recursion tutorial in the Wiki. :D

If you want to see another example of a working iterative file searcher, take a look at the RecFileListToArray UDF in my sig. Feel free to make use of any of the code in there if it helps you. ;)

M23

P.S. You can easily find out if the returned value from FileFindNextFile is a folder or a file by looking at @extended - it is set to 1 for folders as explained in the Help file. :D


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Well Thanks M23 Tht Helped me Out

But im still not getting it why isnt my Function isnt working in my computer.....................

If anyone gets the reason why isnt it running on my computer

Please Post The Solution..........

Regards

PhoenixXL


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

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

  • Similar Content

    • Byte11
      By Byte11
      WinSetState ("[CLASS:OpusApp]", "", @SW_SHOWMAXIMIZED) and WinSetState ("[CLASS:OpusApp]", "", @SW_MAXIMIZE) don't maximize the window.  Using WinSetState("[CLASS:OpusApp]","",@SW_RESTORE) allows me to maximize it about 15% of the time. I've tried using  WinMove("[active]",0,0,@Desktopwidth,@Desktopheight), but that only makes it worse. I've also tried putting in a sleep and maximizing it again. Does anyone have a solution?
      Here's my code:
      The startup script is intentionally commented, because I'm not testing it right now. The other comment is just for debugging when I need it. 
       
      UPDATE: When I run two instances of the program, it works almost all the time, but if I copy the code inside the else statement twice it doesn't work at all (despite the fact that it's running the same code just in one program vs two). I also noticed that when I run two instances of it, about 50% of the time when it opens both the windows, it also hits the windows button and types the letter d into the search box. Neither of these actions are in my code. I'm not really sure what's going on. 
    • distancesprinter
      By distancesprinter
      _ArrayDisplay($aArray, "Window Title", "1:", 0, Default, "Column") ; Expected results are rows 1 to the end of the array, all columns. The result is rows 0-1, all columns. The API reference is here:
      https://www.autoitscript.com/autoit3/docs/libfunctions/_ArrayDisplay.htm
       
      Am I doing something wrong?
    • imitto
      By imitto
      Hi!
      I just playing around with _ArrayMin for my next project, but seems like it's not working. I think the code is OK, but I always get the value of $aArray[2][1], not col 2's lowest value (see attached image)

    • nss
      By nss
      Hi all.
       
      Because of me wondering if I could access the key/value pair arrays with the numbers as indexes, I have found out that the zeroth element for some reason doesn't return anything.
      Here's the example:
       
      local $r[2] $r["test1"]="hello" $r["test2"]="how are you" msgbox(64, $r[0], $r[1]) ; prints the ["test2"] but not ["test1"]. Is this even supposed to be a thing?  
       
      BTW, I haven't seen Autoit get updated since 2015; is it abandened or something?
      Any help/clarification appreciated.
    • TheDcoder
      By TheDcoder
      Hello everyone, I discovered a bug yesterday and I posted it at the bug tracker:
      I also made a simple script which can be used to reproduce the bug:
      CreateVariable() ConsoleWrite($sGlobalVariable & @CRLF) Func CreateVariable() Global $sGlobalVariable = "Foobar" EndFunc The bug was closed by @BrewManNH:
      While I partially agree with the above statement, My code was not practical enough... so @mLipok advised me to create a thread on the forums with practical code (Thanks!). That is the point of this thread, I am going to provide the code where I experience this bug/problem .
      I discovered this bug when I was working on one of my projects called "ProxAllium". When the main script finishes execution, Au3Check throws a nasty warning about "variable possibly used before declaration":

      As you can see, the variable is indeed being used after calling the function in which the variable is declared... The warning won't appear if I declare the function ABOVE the variable. As @BrewManNH said, Au3Check reads line by line... I think this should be changed, Au3Check should not throw warnings if the interpreter is able to run the code, at least most of the time anyway!
      So what do you guys think? Is this a valid bug?... and I request those who participate in the discussion not to discuss the code being "poor", that is another thing/thread in itself
      P.S I had already written this once but the forum editor decided to mess up and when I undid (Ctrl + Z) something... This is a poorly written version of that article, I was very frustrated while writing this!