Jump to content

Copy with dir structure


Recommended Posts

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 by MyEarth
Link to comment
Share on other sites

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 by MyEarth
Link to comment
Share on other sites

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 by MyEarth
Link to comment
Share on other sites

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 by MyEarth
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
 Share

  • Recently Browsing   0 members

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