Jump to content

Need "WildCard" for FileCopy Destination


Go to solution Solved by jguinch,

Recommended Posts

Posted

I am automating a complicated install process for a legacy program.

Part of that install is Oracle 9i, during that install we get some random .dll errors that I know how to eleminate.

I need to copy a DLL from the Windows machine into the temporary installation directory while the installer is running.  I have done this before but that Oracle installer always used the same name for the temp install directory, while this one always adds a timestamp to the folder making it "random"

Example install directory:

C:UsersUserNameAppDataLocalTempOraInstall2014-07-16_11-55-22AM

My old script was simple enough:

 
FileCopy("C:\Windows\System32\psapi.dll", @LocalAppDataDir & "\temp\OraInstall*\", 9)
FileSetAttrib( @LocalAppDataDir & "\temp\OraInstall\psapi.dll", "+R")
 
How can I do a simple modification of this so that it will pick up the random timestamp and choose the newest folder?
 
I already tried my best playing with FileFindFirstFile and _FileListToArray as I feel one of those is the key to an easy fix but I just could not get it working.
Posted (edited)

Hey Vicious,

You could use a FileFindNextFile search and get the properties of the folders using >Simucal's Get Extended Properties UDF

It would look something like this:

$dir = "c:\TEMP\"

$hSearch = FileFindFirstFile($dir & *.*)
if $hSearch = -1 then exit
local $i = 0,$hFileTime[1][2]
while 1
   $hFileName = FileFindNextFile($hSearch)
   if @error then exitloop
   _ExpandArray($hFileTime,2)
   $hFile[$i][0] = $hFileName
   $hFile[$i][1] = _GetExtProperty($dir & $hFileName,2)
$i+= 1
Next

$MostRecent = $hFile[0][1]
for $i=1 to uBound($hFile)
  if $hFile[$i][1] > $MostRecent then
   $MostRecent = $hFile[$i][1]
   $ArrayRow = $i
  endif
next

msgbox(0,"Result","The File you're looking for is " & $hFile[$ArrayRow][0])




func _ExpandArray(ByRef $iArray,$dimensions = 1,$update=1,$newval=uBound($iArray)+1)

  if not IsArray($iArray) then return SetError(1,0,-1)

   if $dimensions < 1 then Return SetError(2,0,-1)
   local $tArray = $iArray

   If $dimensions == 1 Then
      ReDim $iArray[$newval]
      for $i = 1 to uBound($tArray) - 1
         if $i = uBound($iArray) then exitloop
         $iArray[$i] = $tArray[$i]
      Next
   ElseIf $dimensions == 2 Then
      if $update==1 Then
         ReDim $iArray[$newval][uBound($iArray,2)]
         for $i = 1 to uBound($tArray,1) - 1
            if $i = uBound($iArray,1) then ExitLoop
            for $x = 0 to uBound($tArray,2) - 1
               if $x = uBound($iArray,2) then ExitLoop
               $iArray[$i][$x] = $tArray[$i][$x]
            Next
         Next
      elseif $update==2 Then
         ReDim $iArray[uBound($iArray,1)][$newval]
         for $i = 1 to uBound($tArray,1) - 1
            for $x = 1 to uBound($tArray,2) - 1
               $iArray[$i][$x] = $tArray[$i][$x]
            Next
         Next
      EndIf
   ElseIf $dimensions == 3 Then
      if $update==1 Then
         ReDim $iArray[$newval][uBound($iArray,2)][uBound($iArray,3)]
         for $i = 1 to uBound($tArray,1) - 1
            for $x = 1 to uBound($tArray,2) - 1
               for $y = 1 to uBound($tArray,3) - 1
                  $iArray[$i][$x][$y] = $tArray[$i][$x][$y]
               Next
            Next
         Next
      ElseIf $update==2 Then
         ReDim $iArray[uBound($iArray,1)][$newval][uBound($iArray,3)]
         for $i = 1 to uBound($tArray,1) - 1
            for $x = 1 to uBound($tArray,2) - 1
               for $y = 1 to uBound($tArray,3) - 1
                  $iArray[$i][$x][$y] = $tArray[$i][$x][$y]
               Next
            Next
         Next
      ElseIf $update==3 Then
         ReDim $iArray[uBound($iArray,1)][uBound($iArray,2)][$newval]
         for $i = 1 to uBound($tArray,1) - 1
            for $x = 1 to uBound($tArray,2) - 1
               for $y = 1 to uBound($tArray,3) - 1
                  $iArray[$i][$x][$y] = $tArray[$i][$x][$y]
               Next
            Next
         Next
      EndIf
   Else
      Return SetError(3,0,-1)
   EndIf
   Return uBound($iArray)
EndFunc

I also threw in my _ExpandArray Function... it isn't documented or anything, as i never really planned for it to be useful for anything more than a script or two, But it's incredibly handy when you need to create an array of which you're not sure the upper bound will be; and in your case, it's probably ideal

Hopefully this helps :)

-Javi

EDIT: I should mention that I haven't tested this, As I don't have AutoIT installed on this machine, But it should at the very least get you on the right tracks :D

Edited by javiwhite

give a man an application, and he'll be frustrated for the day, Teach him how to program applications and he'll be frustrated for a lifetime.

Posted (edited)

#include <File.au3>
#include <Array.au3>

Local $aFileList = _FileListToArray(@LocalAppDataDir & "\temp\", "OraInstall*", 2, 1)
Dim $array[$aFileList[0]][2]
For $i = 1 to $aFileList[0]
   $array[$i-1][0] = $aFileList[$i]
   $array[$i-1][1] = FileGetTime($aFileList[$i], 1, 1)
Next
_ArraySort($array, 1, 0, 0, 1)
;_ArrayDisplay($array)
Msgbox(0,"newest folder", $array[0][0])

?

Edited by mikell
  • Solution
Posted (edited)

or just copy it in all OraInstall* directories

#Include <File.au3>

$aOraDir = _FileListToArray ( @TempDir, "OraInstall*", 2)
If @error Then Exit MsgBox(16, "Error", "Unable to find the installation directory")

For $i = 1 To $aOraDir[0]
    FileCopy("C:\Windows\System32\psapi.dll", @Tempdir & "\" & $aOraDir[$i], 1)
    FileSetAttrib( @Tempdir & "\" & $aOraDir[$i] & "\psapi.dll", "+R")
Next
Edited by jguinch
Posted

Ok thanks guys, will give it a shot.  I tried to use "*" to move to all directories but I was probably using it with a function that does not support it like FileCopy using the array to emulate the process makes sense and would most likely be the solution I use since its simple and its not going to be more than a few folders with small file transfers.

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...