Sort Names

  • Thread starter Thread starter John Adam
  • Start date Start date
J

John Adam

If I have a list like

Abc01

Abc02

Abc03

Abcj01

Abcj02

abcj03

Deg01

Deg02

Deg03

And so on

And I like to sort them in groups (abc01-abc03) and put them in and array
how can this be done

Thanks Adam
 
* "John Adam said:
If I have a list like

Abc01

Abc02

Abc03

Abcj01

Abcj02

abcj03

Deg01

Deg02

Deg03

And so on

And I like to sort them in groups (abc01-abc03) and put them in and array
how can this be done

What's the exact definition of a "group"? Everything except the number
part? Is "Abcj" a "subgroup" of "Abc"? Should every group be stored in
one array after processing the data? Maybe an arraylist of arrays?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Improve your quoting style:
<http://learn.to/quote>
<http://www.plig.net/nnq/nquote.html>
 
Thanks for the fast reply
group 1 (abc01-abc03) group 2 (abcj01-abcj03) and so on.


Thanks Adam
 
John Adam said:
If I have a list like

(double-spaced list removed) :-)

Hi Adam,

Certainly strings can be placed into an array (or some other collection-like
structure) and they can typically be sorted. Perhaps you could describe the
purpose is or what the strings represent. It can turn out that a
linked-list is the perfect solution but that can't be known until the goal
is understood.

What are you trying to do?

Tom
 
HI Tom

I'm trying to sort filenames chm,pdf,zip,rar,pic etc. for this cd/dvd
catalog program
Everything was looking good until I ran into filenames now I am stuck.I
sorted the files by ext. and put them in and arraylist. But I can not find
out how do I separate each files or group of files my name.

Thanks Adam
 
John Adam said:
I'm trying to sort filenames chm,pdf,zip,rar,pic etc. for this cd/dvd
catalog program
Everything was looking good until I ran into filenames now I am stuck.I
sorted the files by ext. and put them in and arraylist. But I can not find
out how do I separate each files or group of files my name.

You sound like you have it almost finished. By "separate" do you want these
grouped into separate arrays? From your description of it I think you will
just end up "walking" the array, testing each filename and doing whatever it
is you want with the name which could include placing it into another array

If you want, you can post some of the code that you have so far. It can be
easier to make suggestions when the code is presented and that way you get a
reply that fits into what you have so far rather than something completely
different.

Tom
 
Lets say you have an arraylist of filenames
(abc01.pdf,abc02.pdf,abc03.pdf (,abcm01.pdf,abcm02.pdf,abcm03.pdf ) and you
wont to separate them.
You wont to put (abc01-abc03) in a new arraylist and remove them from the
old arraylist but keep the (abcm01-abcm03) file names in the old arraylist.

The thing that I can not figure out is how do I make the program understand
that abc01.pdf,abc02.pdf,abc03.pdf are the same filename and
abcm01.pdf,abcm02.pdf,abcm03.pdf are the same filename everything else is
should be a breezes to do

Thanks Adam
 
Hi John,

Just a quickie (I'm in the middle of something)...

How do <you> know that these are the same? What is the simliarity that
<you> can detect?

abc01.foo
abc02.foo

And thus, how do you know that these are <different>? What is the
difference that <you> can detect?

abc01.foo
abcm01.foo

Regards,
Fergus
 
I can detect all but for me to program it is another story
I can program the exp below
But lets say they have different unknown names at designtime
peterpan.foo,happy.foo,sad.foo etc how do i program that.
Is what im trying to understand.

Thanks John
 
John Adam said:
I can detect all but for me to program it is another story
I can program the exp below
But lets say they have different unknown names at designtime
peterpan.foo,happy.foo,sad.foo etc how do i program that.
Is what im trying to understand.

I'm get it a bit more but there is still some ambiguity.

The problem I see in your first example the ABC01, ABCM01 is that while it
would seem checking for "ABC" would work it turns out they might all start
with that. If we knew that there would always be numbers on the end the we
could compare the leading character parts but... this won't work with
peterpan, happy, etc.

But... lots of buts in this one :-) Then I don't know what the categories
would be. If they are just filenames which can exist on the drive let me
make up some:

backup.zip
backup02.zip
backup9.zip
mydog01.png
mydog02.png
temp.jpg
temp.gif
utility.exe
utilities.zip

If those files came back what "groupings" would you like to see?

Also, about your copying them out of the original array. Rather than leave
"some" perhaps you can copy them all off to other arrays. Consider the
first one a temporary one with all the filenames in it... copy filenames out
and simply dump that array. There is seemingly little use for trying to
salvage it for use with whatever is left after you've grouped the names.

I can pretty much tell that everybody is a little confused about what
constitutes a "group" given a bunch of random filenames.

Oh... I just re-read the other message. You wrote that abc01.pdf, abc02.pdf
and abc03.pdf are "the same filename." Is that because you want to ignore
the number? We can _assume_ they are related but we don't know for certain
they are related.
 
Hi John,

|| I can detect all

I take that you mean you can group abc01, abc02, abcm01 and abcm02, but
you didn't tell me <how> - and that was my question. If you ask me how I
differentiate these groups I won't answer "by looking at them". I'll tell you
precisely what it is about them that I use to do any grouping. From that
precise (as possible) description comes an idea for how to program it.

|| I can program the exp below

But I'm not sure what this means (ie. what's an 'exp', and below where)


You've given more examples:
peterpan.foo, sad.foo and happy.foo.
Now my question becomes <really> important.
How do <you> differentiate them?

Please don't think I'm not being serious, I think you have a fairly
complex task here (especially if you are grouping tracks ripped from CD's with
all the different "album - tracknum_artist [trackname] dd-mm-yy" possibilities
that they provide)

It's even possible that your list is too simplified: How about these? Are
they representative of the problem?

Judee Sill - Live - 17 enchanted sky machines.mp3
Judee Sill - Live - 18 down where the valleys are low.mp3
17 - Judee Sill - Live 2 - blackbird.mp3
18 - Judee Sill - Live 2 - the phoenix.mp3
17 - Judee Sill - Misc - That's The Spirit.mp3
18 - Judee Sill - Misc - The Living End.mp3

If you can tell <me> how you decide this, we can certainly tell VB. But we
need a method to start with. That's for you to think about a bit. ;-)

You may, in the end, simply decide to let the user mark out the blocks.
But before we give up and take that route, come back with more of your
thoughts. I approve of doing these sort of things for the User - provided they
aren't stuck with the results, of course. (And it's a fun challenge).

Regards,
Fergus
 
Sorry to all I should not use the word "group" I should have use related ...
The only grouping is if you have files related by the same name exp.
(backup01.zip ,backup02.zip) they will be in the same group but backup9.zip
will not

backup.zip***** arraylist1
backup01.zip***** arraylist2
backup02.zip***** arraylist2
backup9.zip***** arraylist3
mydog01.png ***** arraylist4
mydog02.png****** arraylist 4
temp.jpg***** arraylist5
temp.gif***** arraylist6
utility.exe***** arraylist7
utilities.zip***** arraylist8

Thank John
 
I don't no what the filename will be on the user computer it can be from
peterpan.jpg to Judee Sill - Live - 17 enchanted sky machines.mp3
But I need to find a way to group these files by related filenames.

Now by you adding in these mp3 into it thing just got more complex
I had a few ideas how to do this but now (them mp3) just complex things I
don't no...

You are right I have to think about this for a while but right now im lost
it have to be a better way to do this.

Thanks again John
 
Hi John,

This is an interesting problem and I'd like to see a solution myself. I
have some ideas, too, but am to busy to look into it just yet. :-(

Just to get you started though, what I was hoping you would tell me is
that, within every group, the names have a bit in common and a bit that is
different. (There can be several same/different sections but the one-of-each
is the best to concentrate on for now). But between groups there is more
difference.

It's still a tricky one, though. ;-)

Come back with anything further on this as I (and I'm sure Tom) will be
most glad to help you progress with it.

I assume that your email address is real (it looks it). If I get anything
that might help, I will post it here and also email you.

Regards,
Fergus
 
John Adam said:
Sorry to all I should not use the word "group" I should have use related ....
The only grouping is if you have files related by the same name exp.
(backup01.zip ,backup02.zip) they will be in the same group but backup9.zip
will not

backup.zip***** arraylist1
backup01.zip***** arraylist2

Well okay it is possible... If you really want to do this I think you'll be
writing a pattern matching operation. Something on the order of:

Take the first item from the list and mark it as belonging to list "1"
(don't move them, just mark them.)

Take the next item and match it using whatever criteria you want, extension,
first part of the filename, number of digits, whatever and compare it to all
previous items. If you find that it matches then mark it with the same
number as the match. If it doesn't match assign it a number 1 greater than
the highest number so far.

Repeat for each subsequent item.

When you are done each string has a number that represents which "group" it
belongs to according to the matching rules you've devised. If you don't
like the results you adjust the rules and run it again. Eventually your
rules will work for everything you've tested. Depending upon the complexity
of the rules they will probably match any new file names also but it is
possible that something "leaks"... if items don't get into the proper group
you adjust your rules to handle the new situation.

Note that this doesn't require sorting the filenames or separating them by
extension first. It is completely rule-based.
 
Back
Top