Sign in to follow this  
Followers 0
madasraka

create new variables ?

8 posts in this topic

Im doing basic filesearch, but with the returned result in the loop instead of showind it up in guyctrlcreateedit i want it to create new variable for each found file.

There can be 100's of files found and displaying them in the edit box is good idea to see them, but to read individual file name from editbox is complicated.

IS there a way to make my script to "once found file matchinc the pattern" create new variable and assign filename to that variable ?

This way i dont have to create 1000000 variables in my script in case if there are 1000000 files found :)

$SearchHandle = FileFindFirstFile ($Address & "\" & $Pattern) ;pattern *.*
While 1
    $Search = FileFindNextFile ($SearchHandle)
    If $Search > "" Then
        Assign ("created variable ?",$Search,2) ;2 to create global ?
        GUICtrlSetData ($List,$Search & @CRLF,"Edit") ; put found name into editbox
    Else
        ExitLoop
    EndIf
WEnd

At the "Assign ("created variable ?",$Search,2)" its not creating anything as i would expect it too. Is there something wrong or i dont understand how this works ?

Please help, this bugges me for a very long time and puts my work to limits allot.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#include <GUIConstants.au3>
#include<Array.au3>
$n=0
Local $nFiles[2]
$nFiles[0] = ""
$FileHandle = FileFindFirstFile("C:\Users\Khan\Documents\*.*")
    If Not @error Then
        While 1
            $n=$n+1                     ;Count
            ReDim $nFiles[$n+1]         ;Changes the array size to add one more "Found" file
            $nFiles[$n] = FileFindNextFile($FileHandle)
            If @error Then ExitLoop     ;When it finds no more files with the pattern, it will stop adding file paths to the array.
        WEnd
    EndIf
ReDim $nFiles[$n-1]                     ;Removes the last blank line
$nFiles[0] = $n-2                       ; sets $nFiles[0] to state the number of files found
$GUI = GUICreate("List", 500, 300)
$List = GUICtrlCreateList("", 10, 10, 480, 280)
For $i=1 To $nFiles[0]
    GUICtrlSetData($List, $nFiles[$i] & "|")
Next
GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

$nFiles[0] returns the number of files it found

was this helpful?

Edited by SNawazK786

Share this post


Link to post
Share on other sites

LOL ofcourse i need help

One thing i see here is _ArrayDisplay

I dont need it to be displayed as poped out of nowhere. It must be shown as part of GUI instead of editbox.

But thanks i will look into this harder this time.

Share this post


Link to post
Share on other sites

Using ReDim is not a good idea because it reduces the enumerating speed.

#Include<Array.au3>

$List = ''
$hSearch = FileFindFirstFile(@SystemDir & '\*')
If $hSearch <> -1 Then
    While 1
        $File = FileFindNextFile($hSearch)
        If @error Then ExitLoop
        If Not @extended Then $List &= $File & ';'
    WEnd
EndIf
$List = StringSplit(StringTrimRight($List, 1), ';', 2)
_ArrayDisplay($List)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Ok this is interesting::

My script 1st searches and outputs found files into editbox (not into array)

Then with a press of another button i want to move found files.

Problem is that i cant move those files without stringing whole editbox (somehow) to read individual filenames to move one at the time.

So i thought if once files found and displayed, each found file would also have its own $n bumber to which i can refference in filemove command.

for example:

post-56898-0-50649900-1298766562_thumb.j

Picture shows that there are multiple file names reflected in editbox

How do i read those filenames off that editbox in loop function and move those files (rename in this case)?

I could do the search and move again using your examples, but then it wont be "Move listed" since user might remove some files from the list.

Edited by madasraka

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

bump :)

How do i read those filenames off that editbox in loop function and move those files (rename in this case)?

I could do the search and move again using your examples, but then it wont be "Move listed" since user might remove some files from the list.

If possible then maybe create a new variable for every single found file, so then i can use those variables, but then i dont know how to get this done.

Edited by madasraka

Share this post


Link to post
Share on other sites

madasraka,

Don't know if it is possible...do NOT think that it is advisable!

Why not use Yashied's example and process the files out of an array..it is plenty quick

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

madasraka,

ALso: you are referencing an "edit box" but the code provided uses a list control. Guictrlread handles both, but differently.

kylomas

addendum: I wrote a possible solution to this post but did not provide for dynamic renaming..was working on that but is now on the back burner.

Am interested in whatever solution you come up with.

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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