Jump to content

MayBe A Bug Or Maybe Windows Problem


Recommended Posts

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.

Link to comment
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?

Link to comment
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.

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
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.

Link to comment
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
 Share

×
×
  • Create New...