Sign in to follow this  
Followers 0
slipsystem

File Delete without deleting folders?

2 posts in this topic

Hey Guys I am busy trying to write a script to help users easily port apps and themes for android devices.

what the script is meant to do is compare two folders.

the user can select whether he/she wants to delete all the files with the same name or only keep files with the same name.

the problem is when generating a list it creates an entry for the folder eg. (/system/framework)

before it does anything it notices that /system/framework exists in both folders and deletes the folder before it check the contents inside the folder eg. /system/framework/framework-res.apk 

so in short it deletes the folders even though the files inside have different names.

here is my script

The problem is in the Remove()

so in other words if the base folder contains files

/system/app/hello.apk

/system/framework/tw.apk

and the port contains

/system/app/hello.apk

/system/framework/tw.apk

/system/framework/framework-res.apk

 

it must delete

/system/app/hello.apk

/system/framework/tw.apk

and keep

/system/framework/framework-res.apk

instead it deleting everything because the folder has the same name

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <File.au3>
DirCreate("Base")
DirCreate("Port")
DirCreate("bin")
MsgBox(0,"Theme Porter","Copy the base zip to base folder and port zip to port folder then click on ok")
FileInstall("C:\Users\Kaylee\Desktop\Port Tool\Tools\7za.exe", @ScriptDir & "\bin\7za.exe")
BaseEx()
PortEx()
GUI()
MsgBox(0,"Theme Porter", "Ok Im done happy modding")


Func BaseEx()
    ; Assign a Local variable the search handle of all files in the current directory.
    Local $hSearch = FileFindFirstFile(@ScriptDir & "\Base\*")

    ; Check if the search was successful, if not display a message and return False.
    If $hSearch = -1 Then
        MsgBox($MB_SYSTEMMODAL, "", "Realy? you didnt read the first message")
        Return False
    EndIf

    ; Assign a Local variable the empty string which will contain the files names found.
    Local $sFileName = "", $iResult = 0

    While 1
        $sFileName = FileFindNextFile($hSearch)
        ; If there is no more file matching the search.
        If @error Then ExitLoop

        ; Display the file name.
ShellExecuteWait(@Scriptdir & "\bin\7za.exe", "x " & $sFileName,@Scriptdir & "\Base")
FileDelete(@ScriptDir & "\Base\" & $sFileName)
            WEnd

    ; Close the search handle.
    FileClose($hSearch)
 EndFunc   ;==>Example

 Func PortEx()
    ; Assign a Local variable the search handle of all files in the current directory.
    Local $hSearch = FileFindFirstFile(@ScriptDir & "\Port\*")

    ; Check if the search was successful, if not display a message and return False.
    If $hSearch = -1 Then
        MsgBox($MB_SYSTEMMODAL, "", "Realy? you didnt read the first message")
        Return False
    EndIf

    ; Assign a Local variable the empty string which will contain the files names found.
    Local $sFileName = "", $iResult = 0

    While 1
        $sFileName = FileFindNextFile($hSearch)
        ; If there is no more file matching the search.
        If @error Then ExitLoop

        ; Display the file name.
ShellExecuteWait(@Scriptdir & "\bin\7za.exe", "x " & $sFileName,@Scriptdir & "\Port")
FileDelete(@ScriptDir & "\Port\" & $sFileName)
            WEnd

    ; Close the search handle.
    FileClose($hSearch)
 EndFunc   ;==>Example


Func Remove()
ShellExecuteWait(@ComSpec , "/c dir /s/b/o:n > list.txt", @ScriptDir & "\Base")
$file = @ScriptDir & "\Base\list.txt"
FileOpen($file, 0)
MsgBox(0,"Theme Porter", "Ok I will get to work and dont worry I will tell  you when I am done",3)
For $i = 1 to _FileCountLines($file)
    $line = FileReadLine($file, $i)
    $length = StringLen(@ScriptDir & "\Base\")
    $newline = StringTrimLeft($line,$length)
if FileExists(@Scriptdir & "\Port\" & $newline) = 1 Then
   FileDelete(@Scriptdir & "\Port\" & $newline)
   EndIf
Next
FileClose($file)
FileDelete($file)
   EndFunc

Func Keep()
ShellExecuteWait(@ComSpec , "/c dir /s/b/o:n > list.txt", @ScriptDir & "\Port")
$file = @ScriptDir & "\Port\list.txt"
FileOpen($file, 0)
MsgBox(0,"Theme Porter", "Ok I will get to work and dont worry I will tell  you when I am done",3)
For $i = 1 to _FileCountLines($file)
    $line = FileReadLine($file, $i)
    $length = StringLen(@ScriptDir & "\Port\")
    $newline = StringTrimLeft($line,$length)
if FileExists(@Scriptdir & "\Base\" & $newline) = 0 Then
   FileDelete(@Scriptdir & "\Base\" & $newline)
   EndIf
Next
FileClose($file)
FileDelete($file)
   EndFunc


   Func GUI()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Theme Porter",220,230)
    Local $idRemove = GUICtrlCreateButton("Remove Files With Same Name", 10, 10, 200, 100)
Local $idKeep = GUICtrlCreateButton("Only Keep Files With Same Name", 10, 120, 200, 100)
    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
             Case $idRemove
                Remove()
                ExitLoop
             Case $idKeep
                Keep()
                ExitLoop
        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

Thanks in advanced

Share this post


Link to post
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
Sign in to follow this  
Followers 0