JohnSte Posted August 25, 2014 Share Posted August 25, 2014 Greetings, I am trying to do the following: On Machine #1, read a list of subdirectories under a root directory On Machine #2, confirm the subdirectories from Machine #1 exist On Machine #2, if a subdirectory does *not* exist, create it I know how to create an array (and have done that, as this task actually encompasses more than two machines) but I don't know how to get a list where I don't know the members (the subdirectory list changes frequently) and I don't know how to then confirm the machines' directory listings match. Thanks in advance for any ideas, or please feel free to point me to a resource I missed. Thanks! John Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 26, 2014 Moderators Share Posted August 26, 2014 JohnSte,I would use _FileListToArrayRec to list the subdirectories on machine #1 (the function does list subfolders as well as files) - use the option to get the full path returned. Then on subsequent machines loop through the array using FileExists (this function works for paths too) to see if they exist - use DirCreate if one does not. Good enough, or do you also need to remove any folders which should not be there? M23 JohnSte 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
JohnSte Posted August 26, 2014 Author Share Posted August 26, 2014 Thank you, that is the function I need. What I would like to do to test is actually display the array - what is the best way to do that? I do not need to remove any folders, fortunately Link to comment Share on other sites More sharing options...
sahsanu Posted August 26, 2014 Share Posted August 26, 2014 If you take a look to example script in _FileListToArrayRec() function you'll find it ;-) Link to comment Share on other sites More sharing options...
sahsanu Posted August 26, 2014 Share Posted August 26, 2014 I'm a bit bored so... Script to be used on machine 1: #include <Array.au3> #include <File.au3> $sPathMachine1 = @ScriptDir & "\root_folder_machine1" ;path to root folder on machine 1 $aListMachine1 = _FileListToArrayRec($sPathMachine1, "*", $FLTAR_FOLDERS, $FLTAR_RECUR, $FLTAR_SORT) ;_ArrayDisplay($aListMachine1) ;uncomment this line if you want to view the list of dirs found on machine 1 _FileWriteFromArray(@ScriptDir & "\listdir_machine1.txt", $aListMachine1, 1) Copy the file created "listdir_machine1.txt" to machine 2, then execute this script: #include <Array.au3> #include <File.au3> $sPathMachine2 = @ScriptDir & "\root_folder_machine2" ;path to root folder on machine 2 $sPathListMachine1 = @ScriptDir & "\listdir_machine1.txt" ;path to file copied from machine 1 which contains the list of dirs Local $aListMachine1 _FileReadToArray($sPathListMachine1, $aListMachine1) ;read the file and put the content in an array ;_ArrayDisplay($aListMachine1) ;uncomment this line if you want to view the array created For $i = 1 To $aListMachine1[0] $sCheckPath = $sPathMachine2 & "\" & $aListMachine1[$i] If Not FileExists($sCheckPath) Then ;here you should write the code to create the dirs ConsoleWrite("This dir should be created on machine 2: " & $sCheckPath & @CRLF) EndIf Next There are several comments inside the code. I hope this could be a start to write your own script Cheers, sahsanu Link to comment Share on other sites More sharing options...
JohnOne Posted August 26, 2014 Share Posted August 26, 2014 Thank you, that is the function I need. What I would like to do to test is actually display the array - what is the best way to do that? I do not need to remove any folders, fortunately _ArrayDisplay() AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
JohnSte Posted August 28, 2014 Author Share Posted August 28, 2014 sahsanu, thank you! Unfortunately the approach here is to have a third machine running the script, with access to both machine 1 and machine 2. JohnOne, thank you too that is exactly what I needed. Ideally what I want to happen is to create an array of the directories on machine 1 under a specific directory, then do the same on machine 2. Then, for each entry on machine 1's array, check to see if the entry exists on machine 2. If it does, copy the files to machine 2; if it does not, create the directory on machine 2, then copy the files. When all this is done, I am now told, I *do* need to delete the files from machine 1. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now