Jump to content

variable folder name


Recommended Posts

still working on that AV script. not easier anymore, but a challenge for me so its interesting :)

Basically trying to run an exe in a folder with a variable name.

C:\folder\folder\VERSION\target.exe

my boss gave me this

$SourceFolder = "C:\Versiontest\"
_ScanFolder($SourceFolder)

Func ScanFolder($SourceFolder)
   Local $Search
   Local $File
   Local $FileAttributes
   Local $FullFilePath

   $Search = FileFindFirstFile($SourceFolder & "\*.*")
 
   While 1
      If $Search = -1 Then
         ExitLoop
      EndIf

      $File = FileFindNextFile($Search)
      If @error Then ExitLoop
      MsgBox(0, "", $File)

      $FullFilePath = $SourceFolder & "\" & $File
      $FileAttributes = FileGetAttrib($FullFilePath)

      If StringInStr($FileAttributes,"D") Then
     ScanFolder($FullFilePath)
      Else
     LogFile($FullFilePath)
      EndIf
 
   WEnd
 
   FileClose($Search)
EndFunc

and i know it's not what i want, but its close and i just cant get it to work. any ideas?

just to clarify, the VERSION folder is renamed to the current version of the program with every update.

Link to comment
Share on other sites

actually this is working (ALMOST!!) just need to fix my issue with the messagebox in success returning 0. not sure what i missed.

$Parent = "C:TestFolder*"
$Target = "Test.txt"

If FileExists ($Parent) = 1 Then
   $returnvalue = _Search($Parent, $Target)
   MsgBox (0,"Success?", $returnvalue)
Else
   MsgBox(0,"","Folder not found")
EndIf


Func _Search($Parent, $Target)
   $Search = FileFindFirstFile($Parent & "*.*")
   While 1
      If $Search = -1 Then ExitLoop
      
      $File = FileFindNextFile($Search)
      If @error Then ExitLoop
      MsgBox(0,"Search Subroutine", $File)
      
      $FullPath = $Parent & "" & $File
      If $File = $Target Then
         Return $FullPath
      Else
         $FileAttr = FileGetAttrib($FullPath)
         If StringInStr( $FileAttr, "D") Then
            _Search($FullPath, $Target)
         EndIf
      EndIf
   WEnd
        
EndFunc
Link to comment
Share on other sites

ok. found some minor issues. MsgBox(0,"", $FullPath) works before the Return $FullPath, but when i MsgBox(0,"", $returnvalue) i get zero...

$Parent = "C:TestFolder"
$Target = "Test.txt"

If FileExists ($Parent & "*") = 1 Then
   $returnvalue = _Search($Parent, $Target)
   MsgBox (0,"Success?", $returnvalue)
Else
   MsgBox(0,"","Folder not found")
EndIf


Func _Search($Parent, $Target)
   $Search = FileFindFirstFile($Parent & "*.*")
   MsgBox(0,"", "in func")
   While 1
      MsgBox(0,"", "start loop")
      If $Search = -1 Then ExitLoop
      MsgBox(0,"", "search = " & $Search )
      $File = FileFindNextFile($Search)
      If @error Then ExitLoop
      MsgBox(0,"Search Subroutine", $File)
      
      $FullPath = $Parent & "" & $File
      If $File = $Target Then
         MsgBox(0,"", "Full path = " & $FullPath)
         Return $FullPath
      Else
         $FileAttr = FileGetAttrib($FullPath)
         If StringInStr( $FileAttr, "D") Then
            _Search($FullPath, $Target)
         EndIf
      EndIf
   WEnd
        
EndFunc
Edited by RedneckTech
Link to comment
Share on other sites

It is possible that the possible recursion in your code is causing an issue.

When you call a function from within itself it is called recursion, so when your

function returns, it might be that it is returning the value to itself.

That sounds weird I know but its the likely explanation.

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

yea i actually figured that out. I set $savedPath = "" right before the original call to the function and changed the return $FullPath to $SavedPath = $FullPath. Only changes the variable if its successful so If $SavedPath <> "" Then. all good.

Thanks guys! best help as usual!

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