barraroo Posted February 6, 2020 Share Posted February 6, 2020 Hi there, I am trying write a script that begins by moving a folder from a newly inserted USB onto C:\ of the host computer. At the moment I am using DirCopy("X:\Setup","C:\Install_notes\Setup") where X:\ is the USB. Unfortunately, every time I insert the USB into a new computer the USB directory letter will be randomly changed. Is there a way to set the location of the FileMove script as the source directory or any other method of executing this? Link to comment Share on other sites More sharing options...
Subz Posted February 6, 2020 Share Posted February 6, 2020 You could try DriveGetDrive to get an array of removable drives or all then loop through the array and use if fileexists($aDrives[$i] & "\Setup") Then DirCopy(...) barraroo 1 Link to comment Share on other sites More sharing options...
iamtheky Posted February 6, 2020 Share Posted February 6, 2020 You can move the directories relative to the script, but you cannot move the directory that the script is currently running from...because the script is running. you can make a little example in the folder and play with the syntax: ;if the target directory does not exist, then this serves to 'change the folder the name' rather than 'cut and paste'. DirMove(@ScriptDir & "\StartupController" , @ScriptDir & "\testfolder" , 1) ;moves the StartupController Directory to the testfolder directory barraroo 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
barraroo Posted February 6, 2020 Author Share Posted February 6, 2020 1 hour ago, Subz said: You could try DriveGetDrive to get an array of removable drives or all then loop through the array and use if fileexists($aDrives[$i] & "\Setup") Then DirCopy(...) Solution worked perfectly, modified some code from the FileExists() help page to make this: #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> ;Finds the drive path of the USB Local $aArray = DriveGetDrive($DT_REMOVABLE) If @error Then ;An error occurred when retrieving the drives. MsgBox($MB_SYSTEMMODAL, "", "It appears an error occurred.") Else For $i = 1 To $aArray[0] ;Show all the drives found and convert the drive letter to uppercase. ;MsgBox($MB_SYSTEMMODAL, "", "Drive " & $i & "/" & $aArray[0] & ":" & @CRLF & StringUpper($aArray[$i])) If FileExists($aArray[$i]&"\setup\USB_Search_Target") Then ;Removes setup folder because DirCopy is stupid and needs to create a new folder DirRemove("C:\Users\admin\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup") sleep(200) ;Moves main scripts & installers to C:\ DirCopy($aArray[$i]&"\Setup","C:\Install_notes\Setup",1) sleep(200) ;Moves the startup script to startup folder DirCopy($aArray[$i]&"\StartupController","C:\Users\admin\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup",1) sleep(500) Shutdown(6) ;MsgBox(4096,"","Test Works") EndIf Next EndIf 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