Jump to content
NDog

compare similar folder names and keep only one with shortened name

Recommended Posts

NDog

I am trying to come up with something to compare similarly named folders and only keep one. If it finds folders with similar names, I want it to find the common name of the folder, strip the trailing name and remove the unneeded folders, only keeping the renamed folder. Also keep any unique folders.

This is all I have so far. I am not sure what I need to do to compare the folder names...

Please help, thanks!

#include <Array.au3>
#include <File.au3>

$backup_dir = @TempDir & "\drivers"
$array_dirlist = _FileListToArray($backup_dir, "*",2) ; only folders
_ArrayDisplay($array_dirlist,"list of folders")

For $i = 1 To UBound($array_dirlist) - 1
    ConsoleWrite($array_dirlist[$i]&@CRLF)
Next

compare.png

Intel(R) 7 SeriesC216 Chipset Family PCI Express Root Port 1 - 1E10
Intel(R) 7 SeriesC216 Chipset Family PCI Express Root Port 5 - 1E18
Intel(R) 7 SeriesC216 Chipset Family SATA AHCI Controller
Intel(R) 7 SeriesC216 Chipset Family SMBus Host Controller - 1E22
Intel(R) 7 SeriesC216 Chipset Family Universal Serial Bus (USB) Controller - 1E1
Intel(R) 7 SeriesC216 Chipset Family USB Enhanced Host Controller - 1E26
Intel(R) 7 SeriesC216 Chipset Family USB Enhanced Host Controller - 1E2D
NVIDIA High Definition Audio
NVIDIA High Definition Audio#1
NVIDIA High Definition Audio#2
NVIDIA High Definition Audio#3
Realtek High Definition Audio
VMware Virtual Ethernet Adapter for VMnet1
VMware Virtual Ethernet Adapter for VMnet8
Xeon(R) processor E3-1200 v23rd Gen Core processor DRAM Controller - 0150
Xeon(R) processor E3-1200 v23rd Gen Core processor PCI Express Root Port - 0151

 

Edited by NDog
Add image for clarity

Share this post


Link to post
Share on other sites
RaiNote

You could compare similar folders with the Functions of String.au3

I can't help more because I am really bad working with strings.


  • C++/AutoIt/OpenGL Easy Coder
  • I will be Kind to you and try to help you
  • till what you want isn't against the Forum
  • Rules~

 

Share this post


Link to post
Share on other sites
guinness

I can't help more because I am really bad working with strings.

Strings are fundamental to EVERY high-level language I know, so if you can't grasp them now, then there is little chance for you to create anything wonderful!

@NDog

There is a tool by Yashied for syncing files. Perhaps check that out, unless you like a challenge?


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
RaiNote

Strings are fundamental to EVERY high-level language I know, so if you can't grasp them now, then there is little chance for you to create anything wonderful!

^_^ I know I know because that i am learning to work with it constantly .


  • C++/AutoIt/OpenGL Easy Coder
  • I will be Kind to you and try to help you
  • till what you want isn't against the Forum
  • Rules~

 

Share this post


Link to post
Share on other sites
Danyfirex

I think something like this.

 

Updated.

#include <Array.au3>

Local $aFilePaths=["Intel(R) 7 SeriesC216 Chipset Family PCI Express Root Port 1 - 1E10", _
"Intel(R) 7 SeriesC216 Chipset Family PCI Express Root Port 5 - 1E18", _
"Intel(R) 7 SeriesC216 Chipset Family SATA AHCI Controller", _
"Intel(R) 7 SeriesC216 Chipset Family SMBus Host Controller - 1E22", _
"Intel(R) 7 SeriesC216 Chipset Family Universal Serial Bus (USB) Controller - 1E1", _
"Intel(R) 7 SeriesC216 Chipset Family USB Enhanced Host Controller - 1E26", _
"Intel(R) 7 SeriesC216 Chipset Family USB Enhanced Host Controller - 1E2D", _
"NVIDIA High Definition Audio", _
"NVIDIA High Definition Audio#1", _
"NVIDIA High Definition Audio#2", _
"NVIDIA High Definition Audio#3", _
"Realtek High Definition Audio", _
"VMware Virtual Ethernet Adapter for VMnet1", _
"VMware Virtual Ethernet Adapter for VMnet8", _
"Xeon(R) processor E3-1200 v23rd Gen Core processor DRAM Controller - 0150", _
"Xeon(R) processor E3-1200 v23rd Gen Core processor PCI Express Root Port - 0151"]

Local $AFind[] = ["Family", "Audio", "VMnet", "Core processor"]


_ArrayDisplay($aFilePaths)

Local $Exist = False
Local $NewFilePaths[0]
Local $index = 0
Local $Count=0
For $x = 0 To UBound($AFind) - 1
    For $i = 0 To UBound($aFilePaths) - 1
        if $index>1 then
        if not StringInStr($aFilePaths[$i],$NewFilePaths[$index-1]) then $Exist=False
        endif
        $Count=StringInStr($aFilePaths[$i], $AFind[$x])
        If $Count And $Exist = False  Then
            ReDim $NewFilePaths[UBound($NewFilePaths) + 1]
            $NewFilePaths[$index] = Stringleft($aFilePaths[$i],$Count+StringLen($AFind[$x])-1)
            $index += 1
            $Exist = True

        EndIf
    Next

    $Exist = False
Next

_ArrayDisplay($NewFilePaths)

Saludos

Edited by Danyfirex
Update Code.

Share this post


Link to post
Share on other sites
Danyfirex

If you think you want to avoid _FileListToArray

 

#include <Array.au3>


Local $aFilePaths = ["Intel(R) 7 SeriesC216 Chipset Family PCI Express Root Port 1 - 1E10", _
        "Intel(R) 7 SeriesC216 Chipset Family PCI Express Root Port 5 - 1E18", _
        "Intel(R) 7 SeriesC216 Chipset Family SATA AHCI Controller", _
        "Intel(R) 7 SeriesC216 Chipset Family SMBus Host Controller - 1E22", _
        "Intel(R) 7 SeriesC216 Chipset Family Universal Serial Bus (USB) Controller - 1E1", _
        "Intel(R) 7 SeriesC216 Chipset Family USB Enhanced Host Controller - 1E26", _
        "Intel(R) 7 SeriesC216 Chipset Family USB Enhanced Host Controller - 1E2D", _
        "NVIDIA High Definition Audio", _
        "NVIDIA High Definition Audio#1", _
        "NVIDIA High Definition Audio#2", _
        "NVIDIA High Definition Audio#3", _
        "Realtek High Definition Audio", _
        "VMware Virtual Ethernet Adapter for VMnet1", _
        "VMware Virtual Ethernet Adapter for VMnet8", _
        "Xeon(R) processor E3-1200 v23rd Gen Core processor DRAM Controller - 0150", _
        "Xeon(R) processor E3-1200 v23rd Gen Core processor PCI Express Root Port - 0151"]


;~ Create the directries to the test
For $i=0 to UBound($aFilePaths)-1
    DirCreate($aFilePaths[$i])
Next


_ArrayDisplay($aFilePaths);show the directories



Local $AFind[][] = [["Family", "Audio", "VMnet", "Core processor"], _
        [False, False, False, False]]
Local $sFolder = @ScriptDir & "\"

Local $NewFilePaths[0]
Local $index = 0
Local $Count = 0
Local $hSearch = FileFindFirstFile($sFolder & "*.")

While 1
    $sFileName = FileFindNextFile($hSearch)
    If @error Then ExitLoop
    For $i = 0 To UBound($AFind, 2) - 1
        If $index > 1 Then
            If Not StringInStr($sFileName, $NewFilePaths[$index - 1]) Then $AFind[1][$i] = False
        EndIf
        $Count = StringInStr($sFileName, $AFind[0][$i])
        If $AFind[1][$i] = True Then DirRemove($sFolder & $sFileName)
        If $Count And $AFind[1][$i] = False Then
            ReDim $NewFilePaths[UBound($NewFilePaths) + 1]
            $NewFilePaths[$index] = StringLeft($sFileName, $Count + StringLen($AFind[0][$i]) - 1)
            DirMove($sFolder & $sFileName, $sFolder & $NewFilePaths[$index])
            $index += 1
            $AFind[1][$i] = True
        EndIf
    Next

WEnd



_ArrayDisplay($NewFilePaths) ;Show the directories that we need and  with  the new names

Saludos

Edited by Danyfirex
I wrote. want avoid instead want to aviod lol

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×