Delete a file with multiple instances and variable path

04/06/2014 21:09 turtlebeach#1
OK, so I'd like to make a part of a script that deletes a file called login.swf

typically, a couple of instances of it will exist after LoL patches and the path can vary, like so:

C:\Riot Games\League of Legends\RADS\projects\lol_air_client\releases\0.0. 1.79\deploy\mod\lgn\themes\loginRumbleSupergalaxy

and

C:\Riot Games\League of Legends\RADS\projects\lol_air_client\releases\0.0. 1.79\deploy\mod\lgn\themes\loginVelkoz


Also, the "0.0.1.79" can change depending on the patch, so it would need to be a wildcard.

I understand I need to use the fuction

FileDelete ( "filename" )

but am not sure how to handle multiple instances of the file as well as the varying path structure. Any help would be much appreciated.
04/06/2014 21:13 alpines#2
You can get the directories in a folder which you don't know what their name is.
[Only registered and activated users can see links. Click Here To Register...]
04/06/2014 21:25 turtlebeach#3
Well I can see how that would be good for finding folders, but don't understand how that helps me find and delete my login.swf

Would it be like ? :

#include <File.au3>
_FileListToArray ("C:\Riot Games\League of Legends\RADS\projects\lol_air_client\releases\", login.swf, 1, True)
04/06/2014 21:56 alpines#4
Didn't you read my post? If you have looked it up on the help file you'll notice that _FileListToArray also returns folders (if you use the right parameters for it) and you wrote that you have different folder names.
_FileListToArray is to find the varying folders and FileDelete for deleting it after you found the folders with _FileListToArray.
04/06/2014 21:59 Paraly#5
PHP Code:
#include <Array.au3>
#include <File.au3>

$LeagueOfLegends_BaseDir RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Riot Games\RADS""LocalRootFolder")
if @
error Then
    $LeagueOfLegends_BaseDir 
RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Riot Games\RADS""LocalRootFolder")
        If @
error Then
            MsgBox
(16,"ERROR","League of Legends dir not found..")
            Exit
        EndIf
EndIf
    
$LeagueOfLegends_BaseDir &= "/projects/lol_air_client/releases/"
    
$dirs _FileListToArray($LeagueOfLegends_BaseDir,"*.*",2)
    
$LeagueOfLegends_BaseDir &= $dirs[1] & "/deploy/mod/lgn/themes/"
    
$dirs2 _FileListToArray($LeagueOfLegends_BaseDir,"*.*",2)
    
$i 1
    
Do
    
FileDelete($LeagueOfLegends_BaseDir $dirs2[$i] & "/login.swf")
    
$i += 1
    Until $i 
UBound($dirs2
04/06/2014 22:16 turtlebeach#6
Quote:
Originally Posted by Paraly View Post
PHP Code:
#include <Array.au3>
#include <File.au3>

$LeagueOfLegends_BaseDir RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Riot Games\RADS""LocalRootFolder")
if @
error Then
    $LeagueOfLegends_BaseDir 
RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Riot Games\RADS""LocalRootFolder")
        If @
error Then
            MsgBox
(16,"ERROR","League of Legends dir not found..")
            Exit
        EndIf
EndIf
    
$LeagueOfLegends_BaseDir &= "/projects/lol_air_client/releases/"
    
$dirs _FileListToArray($LeagueOfLegends_BaseDir,"*.*",2)
    
$LeagueOfLegends_BaseDir &= $dirs[1] & "/deploy/mod/lgn/themes/"
    
$dirs2 _FileListToArray($LeagueOfLegends_BaseDir,"*.*",2)
    
$i 1
    
Do
    
FileDelete($LeagueOfLegends_BaseDir $dirs2[$i] & "/login.swf")
    
$i += 1
    Until $i 
UBound($dirs2
TYVM, that helps a lot!
04/06/2014 22:20 Paraly#7
Quote:
Originally Posted by turtlebeach View Post
TYVM, that helps a lot!
I'm glad I could help, maybe you should try to use the thanks button to say thanks:p
04/06/2014 22:42 alpines#8
Code:
$i = 1 
    Do 
    FileDelete($LeagueOfLegends_BaseDir & $dirs2[$i] & "/login.swf") 
    $i += 1 
    Until $i = UBound($dirs2)
Really? Why don't you use For-Loops instead?
04/06/2014 22:58 Paraly#9
Quote:
Originally Posted by alpines View Post
Code:
$i = 1 
    Do 
    FileDelete($LeagueOfLegends_BaseDir & $dirs2[$i] & "/login.swf") 
    $i += 1 
    Until $i = UBound($dirs2)
Really? Why don't you use For-Loops instead?
Cause I prefer the Do-Loop?

PHP Code:
For $i 1 To UBound($dirs2) - 1
    FileDelete
($LeagueOfLegends_BaseDir $dirs2[$i] & "/login.swf")
Next 
who cares..
04/07/2014 17:38 Arm0100#10
Ha ha ha

Why AutoIt have 3 loop function
I always use For and While but I use Do a little or never :'(
04/07/2014 18:01 butter123#11
While/For: The expression is tested before the loop is executed so the loop will be executed zero or more times.
Do: The expression is tested after the loop is executed, so the loop will be executed one or more times.