On Apr 3, 12:51*pm, Masta <mllo...@areagrup.comwrote:
Hello Group.
I have a directory with 3000 ".jpg" named like this:
1234_01.jpg
1234_09.jpg
1234_11.jpg
1234_12.jpg
2341_01.jpg
2341_05.jpg
2341_06.jpg
2341_08.jpg
2341_09.jpg
(...)
Four figures (product reference) followed by "_"
I need to copy one file of each reference to another directory.
I don't think you can do that with just one scan of the files in the
directory, that is by using a search string to return just one file
that has a unique value in the first four characters of the file name.
I would tackle it like this. I would generate a list of all possible
files with a Directory.GetFiles method call. Then I would loop through
the list an pick off the first four chacacters with a String.Substring
method call. I would add the four letter value to a generic List(Of
String), but only if it hasn't been added yet. Just use the
List.Contains method to check that. Next I would loop through the list
and do a Directory.GetFiles method call specifying a search string of
<first four letters>*.jpg. Pick one them to copy, either random, the
first one, the last one, whatever floats your boat, and copy it with
the File.Copy method.