Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, need to have some idea or solution on below statement.

Let say I have put 3 path into a list.

Path 1-- D:\Images\HV9411FP87_Lot1\_Vision1\Fail\123.jpg

Path 2-- D:\Images\HV9411FP87_Lot1\_Vision1\Fail

Path 3-- D:\Images\HV9411FP87_Lot1\_Vision1\Fail\1234.jpg

Question 1: When I select Path 2 added into list, I need Path 1 to be remove from list.

Question 2: Since Path 2 will copy all .jpg files inside the path, lets assume path 1 has been removed (solve question 1), if I select Path 2, after that if want select Path 3, it will not allow me so select Path 3 due to all image files already copy from Path 2.

Currently I'm using C# WPF.

What I have tried:

Currently i have try to add the list from treeview. after done added, press a button to store all the path into a list.
Posted
Updated 28-May-20 2:34am
Comments
Maciej Los 28-May-20 5:34am    
Do you want to get unique directories?
Member 14844823 28-May-20 5:50am    
Yes. If i add path 2 into list, it will only have Path 2. This is because if i add-in Path 2, means it will copy all images in Fail folder.

If I didn't add Path 2 into list, i can simply add Path 1 and Path 3. this is because i will go each individual image (Path 1 and Path 3) and copy it out.
Maciej Los 28-May-20 6:06am    
🤔
Richard MacCutchan 28-May-20 5:49am    
Where is the code that is copying these files, and why does that affect the content of the existing paths?
Member 14844823 28-May-20 5:58am    
Will develop the code for coping files after find out solution for Question 1 and Question 2, as i will copy the files from the list.

Because it might affect the time of copy. As i know, i can use overwrite = true when File.Copy.

1 solution

You could use the Path.GetRelativePath(String, String) Method (System.IO) | Microsoft Docs[^] to test whether added path is relative to others:
C#
string pathToAdd = @"the\path\to\add";
if (!theList.Any(p => Path.GetRelativePath(p, pathToAdd) == p))
{
   // None of existing paths is relative to the new path, so add it
   theList.Add(pathToAdd);
}
 
Share this answer
 
Comments
Maciej Los 28-May-20 9:09am    
Looks perfect to me ;)
phil.o 28-May-20 9:14am    
Thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900