View previous topic :: View next topic |
Author |
Message |
dave99 Newbie
Joined: 15 Jun 2001 Posts: 24 Location: Torquay, Devon, United Kingdom
|
Posted: Sat Jun 29, 2002 3:15 pm Post subject: Removing Duplicates |
|
|
Well, not quite...
I have pulled a filelist from a folder into a list. There may be more than one file with the same name, but a different extension. So, if I have filename.txt and filename.pdf, I want to remove filename.txt and keep filename.pdf
Make sense?
Cheers
Dave |
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Sun Jun 30, 2002 12:00 am Post subject: |
|
|
Here ya go. Make sure you use a sorted list...
I removed the first example.
Code: |
OPTION SCALE, 96
OPTION DECIMALSEP, "."
TITLE By Mac
DIALOG CREATE,Test Prog,-1,0,300,200
DIALOG ADD,BUTTON,Remove,5,5,120,20,"Remove Duplicates"
DIALOG ADD,BUTTON,Reset,5,126,40,20
DIALOG ADD,TEXT,T1,8,170,,,"Keep this extension"
DIALOG ADD,EDIT,E1,5,265,30,20,"pdf"
DIALOG ADD,LIST,L1,30,5,290,165,,SORTED
DIALOG SHOW
rem -- Add horizontal scroll to list --
%z = @sendmsg(@winexists(~L1),$0194,2000,0)
LIST CREATE, 1
goto ResetBUTTON
:EVLOOP
WAIT EVENT
goto @event()
:RemoveBUTTON
if @not(@dlgtext(E1))
INFO Enter an extension in the edit box...@tab()
goto EVLOOP
end
%%ext = @dlgtext(E1)
if @greater(@pos(".", %%ext), 0)
INFO Do NOT include a period in the extension...@tab()
goto EVLOOP
end
%x = 0
REPEAT
if @greater(@pred(@count(L1)), %x)
rem -- Check for duplicates names --
if @equal(@name(@item(L1, %x)), @name(@item(L1, @succ(%x))))
rem -- Add all duplicates to LIST 1 and remove from L1 --
%%name = @name(@item(L1, %x))
REPEAT
LIST ADD, 1, @item(L1, %x)
LIST DELETE, L1
UNTIL @not(@equal(@name(@item(L1)),%%name))
rem -- Now find correct exension in LIST 1 --
%y = 0
REPEAT
if @equal(%%ext, @ext(@item(1, %y)))
%%found = @item(1, %y)
LIST ADD, L1, %%found
end
%y = @succ(%y)
UNTIL %%found @equal(%y, @count(1))
rem -- If extension not found, keep them all --
if @not(%%found)
%y = 0
REPEAT
LIST ADD, L1, @item(1, %y)
%y = @succ(%y)
UNTIL @equal(%y, @count(1))
end
%%found = ""
LIST CLEAR, 1
end
end
%x = @succ(%x)
UNTIL @greater(%x, @pred(@count(L1)))
goto EVLOOP
:ResetBUTTON
LIST CLEAR, L1
LIST ADD, L1, "apple.pdf.txt"
LIST ADD, L1, "apple.pdf.doc"
LIST ADD, L1, "apple.pdf.pdf"
LIST ADD, L1, "orange.txt"
LIST ADD, L1, "orange.pdf"
LIST ADD, L1, "orange.doc"
LIST ADD, L1, "banana.txt"
LIST ADD, L1, "banana.pdf"
LIST ADD, L1, "banana.doc"
LIST ADD, L1, "aardvark.pdf"
LIST ADD, L1, "monkey.txt"
LIST ADD, L1, "zebra.doc"
LIST ADD, L1, "aapdf.pdf"
LIST ADD, L1, "aapdf.txt"
LIST ADD, L1, "aapdf.doc"
goto EVLOOP
:CLOSE
EXIT
|
Cheers, Mac _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
Last edited by Mac on Mon Jul 01, 2002 4:42 pm; edited 14 times in total |
|
Back to top |
|
|
dave99 Newbie
Joined: 15 Jun 2001 Posts: 24 Location: Torquay, Devon, United Kingdom
|
Posted: Sun Jun 30, 2002 12:19 am Post subject: |
|
|
Mac
To the rescue (as usual)...
Thanks mate!
Best
Dave
|
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Sun Jun 30, 2002 12:39 am Post subject: |
|
|
No problem Dave.
BTW, if there are duplicate filenames and none of them have
the extension you want, they are all deleted. So I added another
program to my first post that doesn't remove any items if the
extension isn't found among the duplicates.
Cheers, Mac _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
|
|
Back to top |
|
|
dave99 Newbie
Joined: 15 Jun 2001 Posts: 24 Location: Torquay, Devon, United Kingdom
|
Posted: Sun Jun 30, 2002 5:58 pm Post subject: |
|
|
The second instance suited my purposes admirably...
Thanks Mac
Dave |
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Sun Jun 30, 2002 9:30 pm Post subject: |
|
|
OK, just one more fix (hopefully)...
If filenames contain the text of an extension (such as applepdf.txt),
@match() may find this part of the filename as the extension.
To fix the problem, I changed this line:
if @match(1, %%ext)
to this:
if @match(1, "."%%ext)
This assures that the extension is checked, unless there's more
than one period in a filename. And even then, the bogus extension
would have to be preceded by a period (such as apple.pdf.txt) to
cause any problems. Hopefully this would rarely (if ever) happen.
The posted code has been changed.
Cheers, Mac _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
|
|
Back to top |
|
|
dave99 Newbie
Joined: 15 Jun 2001 Posts: 24 Location: Torquay, Devon, United Kingdom
|
Posted: Sun Jun 30, 2002 9:36 pm Post subject: |
|
|
Yes...this CAN happen in the environment I'm targeting!
Good point!
Thanks
Dave
|
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Sun Jun 30, 2002 10:30 pm Post subject: |
|
|
Well, I think I've about rode this horse to death... 8O
I changed the code once more. I omitted @match(),
and used a repeat loop that checks the extension of
each duplicate item against %%ext. This works now
with filenames such as APPLE.PDF.TXT, or hopefully
anything else the user can dream up.
Also added a check for the user adding a period to
the extension.
I did NOT replace @match() in the first example, since
you're not using it anyway.
Cheers, Mac _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
|
|
Back to top |
|
|
dave99 Newbie
Joined: 15 Jun 2001 Posts: 24 Location: Torquay, Devon, United Kingdom
|
Posted: Mon Jul 01, 2002 1:25 pm Post subject: |
|
|
Mac
I'm sorry to say, but you're example appears broken since that last modification?
Just pasted into VDS as-is and I'm getting all the apples...
Dave
8O |
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Mon Jul 01, 2002 4:20 pm Post subject: |
|
|
Well, my example works, but there's something wrong with
pasting and copying the code.
I've reposted it several times using both the CODE and VDS
tags. But when I copy it, it doesn't work.
I'll email it to ya.
Cheers, Mac _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
|
|
Back to top |
|
|
Mac Professional Member
Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Mon Jul 01, 2002 4:46 pm Post subject: |
|
|
OK, I finally figured out (and fixed) the problem.
I changed the ResetBUTTON routine from LOADTEXT
to use LIST ADD.
The board adds spaces (line feed chars or whatever) to
the end of each line. This was added to the filenames by
LOADTEXT when you copied it. When the routine used
@match() it didn't matter, but checking the @ext() of the
items picked up the added chars.
Tommy, is there any workaround for this? I tried closing
the LOADTEXT lines with quotation marks, but then the
program adds that to the extension.
Cheers, Mac _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|