Sign in to follow this  
Followers 0
dirty

Edit box selected files separated with |

22 posts in this topic

#1 ·  Posted (edited)

I was wondering why

FileOpenDialog ("Select files", "", "UT3 files (*.upk;*.u;*.ut3)",1+4)

Would return values as

C:\Folder\Filename.upk

Filename2.upk

Filename3.upk

instead of

C:\Folder\Filename.upk

C:\Folder\Filename2.upk

C:\Folder\Filename3.upk

?

Is there a way to get all selected files return full path for each of them ?

One other thing is that (i am using "guictrlcreatelist") returned value is 1 line separated by '|' character which if i was to use guictrlcreateedit would pose a problem and output it to edit box as a single line. Thats kinda why i went with inputbox instead of editbox.

I was looking into help file (like i always do before asking for help) i found that

Opt("GUIDataSeparatorChar", "Character")

would do the trick caz all i wanted is to separate them with

@CRLF

so i would get new line each time, but that didnt work and i cant find any examples on that option anywhere i looked.

Goal is simple, i would have to give a command to console application to process list of selected files one by one but not sure how am i going to do that yet.

All i have done is created GUI with all $vars Cases Ifs and error checks and all i need even $vars for commands, all thats left is this confusing part where lines are not separated as i was expecting (with new line)

I am using:

Opt("GUIDataSeparatorChar", @CRLF)
$UT3List = GUICtrlCreateedit ("",10,180,380,192)
$UT3FilesBrowser = FileOpenDialog ("Select files", "", "UT3 files (*.upk;*.u;*.ut3)",1+4)
GUICtrlSetData ($UT3List, $UT3FilesBrowser, "Edit")

Anyone have time to help ?

Edited by dirty

Share this post


Link to post
Share on other sites



I would think the helpfile is clear enough about what is returned so the rest is up to you to arrange in your script.

Return Value

Success: Returns the full path of the file(s) chosen. Results for multiple selections are "Directory|file1|file2|..."


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Its the | i want to replace with @crlf, but Opt("GUIDataSeparatorChar", @CRLF)is not working or replacing | with @crlf

Share this post


Link to post
Share on other sites

Its the | i want to replace with @crlf, but Opt("GUIDataSeparatorChar", @CRLF)is not working or replacing | with @crlf

As I said: You need to do this in your code after having received the selected files.

Its is really easy when you set your mind to it: StringReplace() for example can do miracles for you.


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

As I said: You need to do this in your code after having received the selected files.

Its is really easy when you set your mind to it: StringReplace() for example can do miracles for you.

Oh thats right i completely forgot about strings managment.

Thanks

Hey while am at it, can you please tell me if there is anyway (maybe using strings) i can get FileOpenDialog to return "Directory\file1" "Directory\file2..." instead of "Directory|file1|file2|..." ?

Caz "Directory|file1|file2|..." is bad and i cant use it at all. Keep in mind that directory could change from file to file.

REason why is

"Full path1\file1.ext" "Full path2\file2.ext"
works

and

"Full path1\file1.ext|file2.ext"
doesnt.

I figured that trying to use command prompt to execute console applications commands.

That app wants full path and file name wraped around with quotes for each filename and i have no clue how to accomplish this even by using strings.

There could be 100's of files and i cant string them all. Theres gotta be something i could do (not without your help)

Thanks Jos.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

$sFiles = FileOpenDialog(......);; If you can't fill this in then STOP HERE!
If StringInStr($sFiles, "|") Then
    $aFiles = StringSplit($sFiles, "", 2)
    For $i = 1 to Ubound($aFiles) -1
        $sStr = '"' & $aFiles[0] & "\" & $aFiles[$i] & '"'
        MsgBox(0, "Result", $sStr);; Do something with the results here
    Next
Else
    $sStr = '"' & $sFiles & '"'
    ;; Do something if it is only a single file selected
EndIf

Edited by GEOSoft

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

#7 ·  Posted (edited)

Hey while am at it, can you please tell me if there is anyway (maybe using strings) i can get FileOpenDialog to return "Directory\file1" "Directory\file2..." instead of "Directory|file1|file2|..." ?

Caz "Directory|file1|file2|..." is bad and i cant use it at all. Keep in mind that directory could change from file to file.

As I said: You need to do this in your code after having received the selected files.

As Geosoft shown you just do that in your script. Edited by Jos
too early in the morning

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

As Geosoft shown you just do that in your script. below a little modification to it to resolve some issues.

$sFiles = FileOpenDialog(...);; If you can't fill this in then STOP HERE!
If StringInStr($sFiles, "|") Then
    $aFiles = StringSplit($sFiles, "", 2)
    For $i = 2 To $aFiles[0]
        $sStr = '"' & $aFiles[1] & "\" & $aFiles[$i] & '"'
        MsgBox(0, "Result", $sStr);; Do something with the results here
    Next
Else
    $sStr = '"' & $sFiles & '"'
    MsgBox(0, "Result", $sStr);; Do something with the results here
    ;; Do something if it is only a single file selected
EndIf

Hmmmmm. I don't see any issues with my version but I do with yours. Check out the 2 in StringSplit().

From the help file

flag = 2, disable the return of the count in the first element - effectively makes the array 0-based (must use UBound() to get the size in this case).


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

Hmmmmm. I don't see any issues with my version but I do with yours. Check out the 2 in StringSplit().

From the help file

meaculpa :mellow:

I guess it is to early still.

You did however have a little typo in the receiving array variable name. :(

Thanks george.


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

meaculpa :mellow:

I guess it is to early still.

You did however have a little typo in the receiving array variable name. :(

Thanks george.

Right you are so lets call it a draw.

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

Right you are so lets call it a draw.

yea.. I can really tell that I am not scripting way as much as I used too a couple of years ago and regularly miss these addition/changes made to functions.

Only scripting I do these days are the supporting scripts like Autoit3Wrapper.

:mellow:


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

oh cool guys thanks a bucket for your help. ill get my dirty hands on your examples as soon as i wash the clue off of them :(

Later that day

Just tried your examples and here is what i got.

In editbox after selecting multiple files with fileopendialog i get.

D:\Unreal Tournament 3\UTGame\CookedPC|Core.u|Editor.u|Engine.u

With your example in place, $sStr returns "63\D"

I dont understand what does that mean but what the hell.

Then i tried it your script only without adding git to my script and nothing at happened at all after selecting multiple files.

It wonly worked when selected single file.

IN your code i only modified

FileOpenDialog ("Select files", "", "UT3 files (*.upk;*.u;*.ut3)",1+4)

First example returns D\ for multiple select and kipped showing this for each letter and second example returned nothing at all for multi select.

Did i forget to add a #include <filename.au3> to your examples ?

I need to modify this:

D:\Unreal Tournament 3\UTGame\CookedPC|Core.u|Editor.u|Engine.u

to this:

"D:\Unreal Tournament 3\UTGame\CookedPC\Core.u" "D:\Unreal Tournament 3\UTGame\CookedPC\Editor.u\" "D:\Unreal Tournament 3\UTGame\CookedPC\Engine.u"

So that each file has full path and wrapped with quotes. :mellow:

Do you guys have any other examples please ?

Edited by dirty

Share this post


Link to post
Share on other sites

dirty,

This works for me:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$UT3List = GUICtrlCreateedit ("",10,180,380,192)

GUISetState()

$UT3FilesBrowser = FileOpenDialog ("Select files", "", "AU3 files (*.au3)",1+4)

; See if multiple files have been selected
If StringInStr($UT3FilesBrowser, "|") Then

    ; Multiple files selected so transform into array
    $aFileList = StringSplit($UT3FilesBrowser, "|")
    ; Now add the filenames into the edit, preceded with the path and ending with @CRLF
    For $i = 2 To $aFileList[0]
        GUICtrlSetData($UT3List, $aFileList[1] & $aFileList[$i] & @CRLF, "1")
    Next
Else
    ; Only a single file selected, so add directly to the edit
    GUICtrlSetData($UT3List, $UT3FilesBrowser & @CRLF)
EndIf

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

I hope it is clear enough. :mellow:

M23


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

#14 ·  Posted (edited)

dirty,

This works for me:

I hope it is clear enough. :mellow: 
M23
[/quote]
"D:\Unreal Tournament 3\UTGame\CookedPCfile1.u" "D:\Unreal Tournament 3\UTGame\CookedPCfile2.u" "D:\Unreal Tournament 3\UTGame\CookedPCfile3.u" 
1 problem
D:\Unreal Tournament 3\UTGame\CookedPCCore.u is actually D:\Unreal Tournament 3\UTGame\CookedPC\file1.u
Backslash was missing.
Also for each file i needed quotes like "D:\Unreal Tournament 3\UTGame\CookedPC\file1.u" "D:\Unreal Tournament 3\UTGame\CookedPC\file2.u" so i modified your example to wrap each result with quotes.GUICtrlSetData($UT3List, '"' & $aFileList[1] &'\' & $aFileList[$i] & '" ', "1")

This will add backslash to before each filename.ext and wrap its full path with quotes.

Man i gotta learn how to with with For $var = 1 to &var2 = 2 things, otherwise i'd be asking for help all the time.

Thank you so much Melba23

Edited by dirty

Share this post


Link to post
Share on other sites

dirty,

Sorry about the missing \. Still catches me out from time to time! :mellow:

M23


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

I hope it is clear enough. :mellow:

M23

<grumble> You and your damn 1 based arrays </grumble>

I have to rewrite so much code to return 0 based arrays that it's becoming tedious.

Look at the built in AutoIt functions that return arrays, 0 based. Look at the majority of UDFs that people write, 1 based. Half of those 1 based arrays are because of StringSplit() and not using the "2" flag. I know, it's because that flag wasn't available for a long time but that doesn't mean that we have to live with it now.


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

George,

I did not write StringSplit, nor did I arrange for FileOpenDialog to return that ridiculous string! :mellow:

And to think I was cheering on Canada in the ice hockey final last night - some people have no sense of gratitiude! :lol:

M23

P.S. Besides, until someone changes UBound to return the last element index as you would expect, I am more than happy with the count in [0]! :(


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

George,

I did not write StringSplit, nor did I arrange for FileOpenDialog to return that ridiculous string! :mellow:

And to think I was cheering on Canada in the ice hockey final last night - some people have no sense of gratitiude! :lol:

M23

P.S. Besides, until someone changes UBound to return the last element index as you would expect, I am more than happy with the count in [0]! :(

I just needed someone to pick on. And Ubound($array) -1 doesn't bother me at all and I even use it for 1 based arrays. Although I must admit it would be nicer if it did return the last element index. Unfortunatly that would be a major script breaker, but we've done those before too.

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

#19 ·  Posted (edited)

As UBound basically is the equivalent of .size() or .length() in other programming languages I strongly disagree with making it return the index of the last element. It should return the number of elements, as it does right now. The following ugly syntax (imo)

For $i = 0 To Ubound($anArray)-1
    ; Do Something with $anArray[$i]
Next

... should just be replaced by something much more elegant like

Foreach $anArray as $anElement
    ; Do Something with $anElement
FEnd

Then we wouldn't have people discuss what UBound should return -- only that it should be renamed to ArraySize :mellow: Don't get me wrong, For loops are fine but I do not in any way admire it's syntax when used with arrays.

Edited by d4ni

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

what a debate :(

By the way my thing is almost over and i was wondering yif you guys could help me with one last thing.

How to search directory and and its subdirectories for .uz3 file formats and then move them to other place ?

Kinda like

$Dir = "C:\"
$Search = FileFindFirstFile ($Dir & "*")
While 1
    $FindNext = FileFindNextFile ($Search)
    $GetExt = StringRight ($FindNext,4)
    FileCopy ($Dir & $FindNext & "*.txt", @DesktopDir,1)
    MsgBox(0,'',$FindNext & ' copied')
If $FindNext = "" Then ExitLoop
WEnd

Somehow it copies files only after loop exits or am just going crazy :mellow: after all today all i did was typing and eating.

All this does is shows files only from C:\ but not its sub directories.

By the way, i totaly agree with renaming some of the syntax due to me always trying to type

DirOpenDialog when its actually FileSelectFolder

Then why FileOpenDialog is not FileSelectFile ? Now that would be stupid dont you think ? :lol: fileselectfile hahahahah !

Strange

Edit:

I tried to play with array's

$Dir = "C:\"
$array = _FileListToArray ($Dir,'*',2)
_ArrayDelete ($array,0)
$result = _ArrayToString ($array,' ')
MsgBox(0,'',$result)

It gives me names of all sub folders but i am not sure how to use that to my advantage.

Edited by dirty

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