Using Answer dialog within repeat

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
keyless
Posts: 211
Joined: Wed Dec 12, 2007 11:21 pm

Using Answer dialog within repeat

Post by keyless » Mon Mar 17, 2008 8:46 am

I have this repeat below in my code. I am checking for a duplicate file, and notifying the user with Answer dialog and giving them the option to stop or continue. If the user selects Stop for that file (NPath), then I want to remove it from the FilePathList.

What do I use to remove that file from the FilePathList and let the repeat run its course? I use filePathList in other functions and don't want that file/path in there after user choose "stop" for it.

(I left the "if it is "Stop" then..." unfinished)

Code: Select all

repeat for each line NPath in FilePathList
    set the itemDel to "/"
    put last item of NPath into Tfile
    if Tfile is among the lines of Dupefld then
      answer error Tfile & space & "already exists" with "Stop" or "Continue"
      if it is "Stop" then 
      end if
  end repeat

keyless
Posts: 211
Joined: Wed Dec 12, 2007 11:21 pm

Re: Using Answer dialog within repeat

Post by keyless » Mon Mar 17, 2008 9:24 pm

keyless wrote:I have this repeat below in my code. I am checking for a duplicate file, and notifying the user with Answer dialog and giving them the option to stop or continue. If the user selects Stop for that file (NPath), then I want to remove it from the FilePathList.

What do I use to remove that file from the FilePathList and let the repeat run its course? I use filePathList in other functions and don't want that file/path in there after user choose "stop" for it.

(I left the "if it is "Stop" then..." unfinished)

Code: Select all

repeat for each line NPath in FilePathList
    set the itemDel to "/"
    put last item of NPath into Tfile
    if Tfile is among the lines of Dupefld then
      answer error Tfile & space & "already exists" with "Stop" or "Continue"
      if it is "Stop" then 
      end if
  end repeat


UPDATE:
after sleeping on this, I think maybe I will use a "next repeat" in the "if it is "Stop" line."

I will put a line below that with a Put NPath & cr after {a new Variable}.

So, the Next repeat will prevent that stopped NPath from being put into this new variable.

I will of course use this new cleaned variable in the rest of the handlers.


SECOND UPDATE:
Hmmm and now I'm thinking maybe I could just use a "Replace Npath with Empty in FilePathlist for the "if it is "Stop" line."

I think that will work well, let me know if anyof you see a better way.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Tue Mar 18, 2008 11:30 am

Hi Keyless,

I started to write an example script for you and then realized I didn't understand what you are actually trying to do. So, let me answer your question with more questions.

Do you really need those fields? What exactly do you need them for?
Are you copying files, or something else? Do you really need user intervention, or do you actually always want to stop of there is a duplicate? Or do you always want to continue, just skippting the duplicates?

What is the most likely scenario, if there are 100s of duplicates? I'm sure, no use will ever click the Okay button 100s of times.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

keyless
Posts: 211
Joined: Wed Dec 12, 2007 11:21 pm

Post by keyless » Tue Mar 18, 2008 5:50 pm

Mark wrote:Hi Keyless,

I started to write an example script for you and then realized I didn't understand what you are actually trying to do. So, let me answer your question with more questions.

Do you really need those fields? What exactly do you need them for?
Are you copying files, or something else? Do you really need user intervention, or do you actually always want to stop of there is a duplicate? Or do you always want to continue, just skippting the duplicates?

What is the most likely scenario, if there are 100s of duplicates? I'm sure, no use will ever click the Okay button 100s of times.

Best,

Mark
Thanks Mark.
This is about copying files. What I am doing is checking another variable for duplicates & if a duplicate file is found, I want to ask the user if they want to continue and copy the file anyway, or stop the copying of that file. The Filepathlist needs to be adjusted accordingly so it can be passed on to the copy and delete handler. The likely scenario is that there will not be a lot of duplicates, this is just a "just in case"

Code: Select all

Replace Npath with Empty in FilePathlist
doesn't seem to work right. I thought it was working but noticed a problem when I tested with three duplicates and chose stop for all three. 2 of the duplicates copied anyway.

I switched it to

Code: Select all

Filter FilePathList without Npath
but oddly that would work for two duplicate files but not 3 ????

What I ended up doing is just putting each stopped Npath into a new variable [lRemove].

I then used another repeat further down the code:

Code: Select all

repeat for each line OPath in lRemove
    filter FilePathList without OPath
end repeat
This works.

Still baffled why the same thing didn't work inside the original repeat loop, but I suspect it has to do with the fact that the lines were coming from FilePathList, which was being filtered in its own loop. Seems like a bug that it doesn't work though.


I have a second question of what to do about hidden files in Windows (ie Thumbs.db). I don't want them included when the filepaths are put into Filepathlist. Is there an easy way to filter hidden files out? right now I am just filtering Thumbs.db out, but I suspect this has come up before and there is a simple way to avoid hidden files.

Post Reply