Path Scope Cleaner

Share your advanced PureBasic knowledge/code with the community.
Daorven
New User
New User
Posts: 1
Joined: Thu May 12, 2022 12:07 pm

Path Scope Cleaner

Post by Daorven »

Code: Select all

; ---------------------------------------------------
; "PATH SCOPE CLEANER"
; ---------------------------------------------------
; A small adaptation from "PushListPosition" documentation example.
; https://www.purebasic.com/french/documentation/list/pushlistposition.html
; https://www.purebasic.com/documentation/list/pushlistposition.html
;
; If you do use a recursive function to scan all file (inside all subdirectory) to start
; in specific drive path location, this tips keep only the path near the root drive,
; remove twin path and other path more deep from another know path.
; This may be usefull to determine where you do start to scan
; all wanted file if you have different paths in same drive.
;
; Have a nice day.



; structure with string List
Structure struc_path
  List path.s()
EndStructure
Global p.struc_path

; added some path in any order
AddElement(p\path()) : p\path() = "C:"
AddElement(p\path()) : p\path() = "F:"
AddElement(p\path()) : p\path() = "F:\MOVIE\I_LIKE\TEST\TEST2\I_LIKE\TEST\TEST2"
AddElement(p\path()) : p\path() = "F:\MOVIE\I_LIKE\TEST"
AddElement(p\path()) : p\path() = "F:\MOVIE\I_LIKE\TEST\TEST2"
AddElement(p\path()) : p\path() = "C:\MOVIE\I_LIKE\TEST\TEST2"
AddElement(p\path()) : p\path() = "D:\MOVIE\I_LIKE\TEST\TEST2"
AddElement(p\path()) : p\path() = "D:\MOVIE\I_LIKE\TEST\TEST2\TEST4"
AddElement(p\path()) : p\path() = "D:\SOUND\I_LIKE\TEST\TEST2\TEST4"
AddElement(p\path()) : p\path() = "D:\SOUND\I_LIKE"
AddElement(p\path()) : p\path() = "C:"
AddElement(p\path()) : p\path() = "F:\MOVIE\I_LIKE\TEST\TEST2\I_LIKE\TEST\TEST2"
AddElement(p\path()) : p\path() = "F:\MOVIE\I_LIKE\TEST\TEST2\I_LIKE\TEST\TEST2"
AddElement(p\path()) : p\path() = "G:\MOVIE\I_LIKE\TEST\TEST2\I_LIKE\TEST\TEST2"


; ---------------------- DEBUG ----------------------
s.s = RSet("", 50, "-")
Debug s
Debug "List 'p\path()' without modification."
Debug s 
ForEach p\path() : Debug p\path() : Next
Debug s   
; ---------------------------------------------------

; To this tips work we do have a List sorted by Ascending.
SortList(p\path(), #PB_Sort_Ascending) 

; ---------------------- DEBUG ----------------------
Debug "List 'p\path()' sorted."
Debug s
ForEach p\path() : Debug p\path() : Next
Debug s   
; ---------------------------------------------------

; clean list
ForEach p\path()
  check.s = p\path()         
  PushListPosition(p\path())  
  While NextElement(p\path()) 
      If CountString(p\path(), check) = 1 
          DeleteElement(p\path())
      EndIf
  Wend
  PopListPosition(p\path())
Next

; ---------------------- DEBUG ----------------------
Debug "List 'p\path()' cleaned."
Debug "We have now the minimal paths to scan all wanted."
Debug "We have " + ListSize(p\path()) + " Items in List."
Debug s
ForEach p\path(): Debug p\path() : Next
Debug s   
; ---------------------------------------------------