hpp3 Posted May 24, 2005 Share Posted May 24, 2005 Okay, I've RTFM'd and searched the forum to no avail. I am making a GUI frontend for a command line prog and I need to take a list of files (like when you go ctrl-A in a 'Select File' dialog) and process them one after the other until they are all done. Specifically, converting a list of graphics files from one format to another. I know how to do the GUI, the loop engine is what is baffling me. I have written a script to do single files, so the command operands are no problem. A rough sketch of the workflow goes like this: ; input box -> input file(s) ; input box -> output directory ; wait for "GO" button ; start loop ; get next filename ; RunWait (commandlineprog.exe <input filename> <outputdir/base filename.newextension>) ; If -> any more files? ; Then -> back to loop ; Else -> exit loop ; MsgBox "all done!" It's the "get next filename...any more files" loop that is baffling me. Thanks for help. Link to comment Share on other sites More sharing options...
MarkMarkMark Posted May 24, 2005 Share Posted May 24, 2005 "get next filename" isnt a function.. its Filegetfirst if im right... and then u need Filegetnext.... look it up in the help Link to comment Share on other sites More sharing options...
hpp3 Posted May 24, 2005 Author Share Posted May 24, 2005 "get next filename" isnt a functionYes, I know. I didn't write it as a command, just as a marker for the intended action. As in "somehow parse what the next file in line is so we can run it through the grinder" . As I read in the help there is no "FileGetNext" either, just "FileFindFirst" and "FileFindNext" which are search funtions, not file name processing functions, which is what I need. Perhaps what is needed is a way to push the filenames into an array and then simply step through that array in the loop. Hmmm... Link to comment Share on other sites More sharing options...
Lazycat Posted May 24, 2005 Share Posted May 24, 2005 First of all, how you plan to get filenames (input box -> input file(s))? For example, it's simple to do with standard open dialog, it have option to multilselect files. Then you have to StringSplit them. $ret = FileOpenDialog ( "Open", "init dir", "*.*", 4) $aFN = StringSplit($ret, "|") For $i = 2 to $aFN[0] $curFN = $aFN[1] & "\" & $aFN[$i] RunWait (...) Next Koda homepage ([s]Outdated Koda homepage[/s]) (Bug Tracker)My Autoit script page ([s]Outdated mirror[/s]) Link to comment Share on other sites More sharing options...
hpp3 Posted May 24, 2005 Author Share Posted May 24, 2005 Most helpful lazycat, thank you thank you and thank you again. And yes, I planned on using a standard Open File Dialog, thanks. Next question, any way to extract the base name from... oop, stringsplit again, right? Something like: $aBN = StringSplit ($curFN, ".") $basename = $aBN[1] I'll test this out and post a complete code if it works Thanks all! Link to comment Share on other sites More sharing options...
PerryRaptor Posted May 25, 2005 Share Posted May 25, 2005 Another idea... I would use the MS-DOS command "DIR" with the switches "/B" and "/S" and send the results to a file. Then I would use FileReadLine() to open and read file. I would convert the "File Grinder" into a function and call it into action until the end-of-file is reached. Link to comment Share on other sites More sharing options...
therks Posted May 25, 2005 Share Posted May 25, 2005 Most helpful lazycat, thank you thank you and thank you again. And yes, I planned on using a standard Open File Dialog, thanks. Next question, any way to extract the base name from... oop, stringsplit again, right? Something like:$aBN = StringSplit ($curFN, ".") $basename = $aBN[1]I'll test this out and post a complete code if it works Thanks all!<{POST_SNAPBACK}>Actually, your idea is good, but it can cause problems.I assume what you're expecting is something like this:$a = StringSplit('c:\windows\filename.txt', '.') $a[1] = 'c:\windows\filename' $a[2] = 'txt'Am I correct? This will work fine.. until you find a folder with a period in it (or a filename with more than one).$a = StringSplit('c:\Documents and Settings\User.Account\filename.txt', '.') $a[1] = 'c:\Documents and Settings\User' $a[2] = 'Account\filename' $a[3] = 'txt'See the problem?Your best bet, is to use a couple of functions. Here's what I've had success with.Let's use your variable, $curFN, for the example.First we get the location of the last period (StringInStr), then using StringLeft to pull out the pertinent information:$curFN = 'My.Awesome.File.jpg' $dotPos = StringInStr($curFN, '.', 0, -1) - 1 $baseFN = StringLeft($curFN, $dotPos) msgbox(0,'',$baseFN)See what I mean?I also made up this one if you've got a full path, and want to extract the basename.$curFN = 'C:\Windows\My.Awesome.File.jpg' $dotPos = StringInStr($curFN, '.', 0, -1) - 1 $slashPos = StringInStr($curFN, '\', 0, -1) $baseFN = StringLeft($curFN, $dotPos) $baseFN = StringTrimLeft($baseFN, $slashPos) msgbox(0,'',$baseFN) My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
buzz44 Posted May 25, 2005 Share Posted May 25, 2005 (edited) I find it easiest just to reverse it, that way you will always get the file name first, then you just reverse it again. Of course the method you use will vary each time depending on what information you want to retrieve, for me its usually the file type and the file name.#Include <string.au3> $a = StringSplit(_StringReverse('C:\Windows\My.Awesome.File.jpg'), '\') $Name = StringTrimRight (_StringReverse($a[1]), 4) Msgbox(4096,"Test",$Name) Edited May 25, 2005 by Burrup qq Link to comment Share on other sites More sharing options...
hpp3 Posted May 25, 2005 Author Share Posted May 25, 2005 Saunders - Yes I was aware of the "more than one dot in the file name" problem and was putting that on my to-do list; Thanks for the help there. Burrup - Quite the clever idea, I'll try that, too. Boy, you'd think something like extracting the base name of a file would be a little easier huh? Maybe a function of this type would make a good feature request? It'd be nice (and very useful IMHO) to have like a more specified StringSplit-type function so one could return the basename, directory path, root directory, the filename alone, etc. with one function instead of the gymnastics demonstrated here. Very FINE gymnastics, I might add... Thanks all for your help, I'm almost ready to post code. When I RTFM'd trying to figure all this out, I remember reading through StringSplit and it's relations, but somehow missed the application. Link to comment Share on other sites More sharing options...
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