MyEarth Posted July 30, 2014 Share Posted July 30, 2014 (edited) Let's suppose i have an array of many files. $sStartingDir = "C:\Software\AutoIt3\Aut2Exe" $sFinalDir = "C:\MyFolder" Global $aArray[3] $aArray[0] = "C:\Software\AutoIt3\Aut2Exe\MyFile1.exe" $aArray[1] = "C:\Software\AutoIt3\Aut2Exe\Icons\MyFile2.exe" $aArray[2] = "C:\Software\AutoIt3\Aut2Exe\Icons\Icons2\MyFile3.exe" For $i = 0 To UBound($aArray) -1 ConsoleWrite($aArray[$i] & @CRLF) Next Now i want to copy this file in another dir but having the same structure, so basing on the script it will be: C:MyFolderMyFile1.exe C:MyFolderIconsMyFile2.exe C:MyFolderIconsIcons2MyFile3.exe Suggestion? Thanks Edited July 30, 2014 by MyEarth Link to comment Share on other sites More sharing options...
JohnOne Posted July 30, 2014 Share Posted July 30, 2014 FileCopy and a bit of logic Look at flags. 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...
MyEarth Posted July 30, 2014 Author Share Posted July 30, 2014 (edited) Yes i know i need to use FileCopy with 8 flag for create a dir if not exist, but is the "logic" for get the folder and the subfolder ( if there is a subfolder ) i miss, i have think to use StringSplit but i dunno in which way. Edited July 30, 2014 by MyEarth Link to comment Share on other sites More sharing options...
JohnOne Posted July 30, 2014 Share Posted July 30, 2014 You say keep the structure, but how much of it? 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...
MyEarth Posted July 30, 2014 Author Share Posted July 30, 2014 (edited) The $sStartingDir is C:SoftwareAutoIt3Aut2Exe The logic i miss is for the subfolder or multiple subfolder, if exist a subfolder of Aut2Exe, how to "extract" from the string? In the example the subfolder is Icons, but in theory can exist a subfolder of a subfolder like Icons2 Edited July 30, 2014 by MyEarth Link to comment Share on other sites More sharing options...
MyEarth Posted July 30, 2014 Author Share Posted July 30, 2014 (edited) Well, i have do something like this: $sStartingDir = "C:\Software\AutoIt3\Aut2Exe" $sFinalDir = "C:\MyFolder" $aStartDir = StringSplit($sStartingDir, "\") Global $aArray[3] $aArray[0] = "C:\Software\AutoIt3\Aut2Exe\MyFile1.exe" $aArray[1] = "C:\Software\AutoIt3\Aut2Exe\Icons\MyFile2.exe" $aArray[2] = "C:\Software\AutoIt3\Aut2Exe\Icons\Icons2\MyFile3.exe" For $i = 0 To UBound($aArray) - 1 $aPath = StringSplit($aArray[$i], "\") $sLastFolder = $aPath[UBound($aPath) - 2] & "\" If $sLastFolder = $aStartDir [UBound($aStartDir ) - 1] & "\" Then $sLastFolder = "" ConsoleWrite("Destination: " & $sFinalDir & "\" & $sLastFolder & StringTrimLeft($aArray[$i], StringInStr($aArray[$i], "\", 0, -1)) & @CRLF) Next Work only for the first two path, so without subfolder and with one subfolder, with 2 sub not work as expected... Destionation: C:MyFolderMyFile1.exe -> OK Destionation: C:MyFolderIconsMyFile2.exe -> OK Destionation: C:MyFolderIcons2MyFile3.exe -> Wrong ( C:MyFolderIconsIcons2MyFile3.exe -> Correct ) Edited July 30, 2014 by MyEarth 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