Jump to content

Get directory list on multiple machines

Recommended Posts


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.



Link to comment
Share on other sites

  • Moderators


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? :huh:


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Link to comment
Share on other sites

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)

There are several comments inside the code.

I hope this could be a start to write your own script ;)



Link to comment
Share on other sites

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 :)


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

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

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...