Sign in to follow this  
Followers 0
sourabh343

Remove directory

7 posts in this topic

Hi,

Could anyone please help me out with deleting the folders, i have writen a script for remving the folders using Autoit, but it doesn't remove the folders...I am new to Autoit.

Below is the script which i have writen

#include <Process.au3>
#include <File.au3>
#include <FTPEx.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Func deleteTest()

If FileExists("C:\UGS\TEST") Then
            $res = DirRemove("C:\UGS\TEST", 1)
            If $res = 0 Then
                SplashOff()
                $message = "*** Cleaning up C:\UGS\TEST folder Failed. please remove the folder manually"
                _FileWriteLog($sLogPath, $message)
                MsgBox(0, "TEST cleanup ", $message)
            EndIf
            SplashOff()
            $message = "Cleaning up C:\UGS\TEST folder ...Done"
            _FileWriteLog($slogPath, $message)
EndIf

If FileExists("C:\UGS\Test") Then
            $res = DirRemove("C:\UGS\Test", 1)
            If $res = 0 Then
                SplashOff()
                $message = "*** Cleaning up C:\UGS\Test folder Failed. please remove the folder manually"
                _FileWriteLog($sLogPath, $message)
                MsgBox(0, "Test cleanup ", $message)
            EndIf
            SplashOff()
            $message = "Cleaning up C:\UGS\Test folder ...Done"
            _FileWriteLog($slogPath, $message)
EndIf

EndFunc ;==>removeTest

Regards,

Sourabh

Share this post


Link to post
Share on other sites



25 minutes ago, JohnOne said:

If you use vista or later, #requireadmin to script.

It still doesn't remove the folders after including #requireadmin in the script

Share this post


Link to post
Share on other sites

In your code, you are not calling the deleteTest function.  You are only defining it.  Here is your code updated to run deleteTest.

#include <Process.au3>
#include <File.au3>
#include <FTPEx.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

deleteTest()

Func deleteTest()

    If FileExists("C:\UGS\TEST") Then
        $res = DirRemove("C:\UGS\TEST", 1)
        If $res = 0 Then
            SplashOff()
            $message = "*** Cleaning up C:\UGS\TEST folder Failed. please remove the folder manually"
            _FileWriteLog($sLogPath, $message)
            MsgBox(0, "TEST cleanup ", $message)
        EndIf
        SplashOff()
        $message = "Cleaning up C:\UGS\TEST folder ...Done"
        _FileWriteLog($slogPath, $message)
    EndIf

    If FileExists("C:\UGS\Test") Then
        $res = DirRemove("C:\UGS\Test", 1)
        If $res = 0 Then
            SplashOff()
            $message = "*** Cleaning up C:\UGS\Test folder Failed. please remove the folder manually"
            _FileWriteLog($sLogPath, $message)
            MsgBox(0, "Test cleanup ", $message)
        EndIf
        SplashOff()
        $message = "Cleaning up C:\UGS\Test folder ...Done"
        _FileWriteLog($slogPath, $message)
    EndIf

EndFunc ;==>removeTest

 

Adam

 

Share this post


Link to post
Share on other sites
3 hours ago, AdamUL said:

In your code, you are not calling the deleteTest function.  You are only defining it.  Here is your code updated to run deleteTest.

#include <Process.au3>
#include <File.au3>
#include <FTPEx.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

deleteTest()

Func deleteTest()

    If FileExists("C:\UGS\TEST") Then
        $res = DirRemove("C:\UGS\TEST", 1)
        If $res = 0 Then
            SplashOff()
            $message = "*** Cleaning up C:\UGS\TEST folder Failed. please remove the folder manually"
            _FileWriteLog($sLogPath, $message)
            MsgBox(0, "TEST cleanup ", $message)
        EndIf
        SplashOff()
        $message = "Cleaning up C:\UGS\TEST folder ...Done"
        _FileWriteLog($slogPath, $message)
    EndIf

    If FileExists("C:\UGS\Test") Then
        $res = DirRemove("C:\UGS\Test", 1)
        If $res = 0 Then
            SplashOff()
            $message = "*** Cleaning up C:\UGS\Test folder Failed. please remove the folder manually"
            _FileWriteLog($sLogPath, $message)
            MsgBox(0, "Test cleanup ", $message)
        EndIf
        SplashOff()
        $message = "Cleaning up C:\UGS\Test folder ...Done"
        _FileWriteLog($slogPath, $message)
    EndIf

EndFunc ;==>removeTest

 

Adam

 

Adam, if i run the code after converting it to exe, it is removing folders but i also gives me an error saying

Line 9164 (File "C:\Script\TestCode\deleteTEST.exe"):

Error: Variable used without beign declared

Share this post


Link to post
Share on other sites

I just copied your code and added the function call.  I didn't run AU3Check on it.  If you run AU3Check on the script, it will show that $sLogPath is undefined.  I've updated the script below.  

#include <Process.au3>
#include <File.au3>
#include <FTPEx.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

deleteTest()

Func deleteTest()
    
    Local $sLogPath = "Log File.txt"

    If FileExists("C:\UGS\TEST") Then
        $res = DirRemove("C:\UGS\TEST", 1)
        If $res = 0 Then
            SplashOff()
            $message = "*** Cleaning up C:\UGS\TEST folder Failed. please remove the folder manually"
            _FileWriteLog($sLogPath, $message)
            MsgBox(0, "TEST cleanup ", $message)
        EndIf
        SplashOff()
        $message = "Cleaning up C:\UGS\TEST folder ...Done"
        _FileWriteLog($slogPath, $message)
    EndIf

    If FileExists("C:\UGS\Test") Then
        $res = DirRemove("C:\UGS\Test", 1)
        If $res = 0 Then
            SplashOff()
            $message = "*** Cleaning up C:\UGS\Test folder Failed. please remove the folder manually"
            _FileWriteLog($sLogPath, $message)
            MsgBox(0, "Test cleanup ", $message)
        EndIf
        SplashOff()
        $message = "Cleaning up C:\UGS\Test folder ...Done"
        _FileWriteLog($slogPath, $message)
    EndIf

EndFunc ;==>removeTest

 

Adam

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

1 hour ago, sourabh343 said:

Adam, if i run the code after converting it to exe, it is removing folders but i also gives me an error saying

Line 9164 (File "C:\Script\TestCode\deleteTEST.exe"):

Adam has just added 1 line (https://www.autoitscript.com/forum/topic/184523-remove-directory/?do=findComment&comment=1325416), the new script has same error(s) as your script.

>Running AU3Check (3.3.14.2)  from:C:\Program Files\AutoIt3  input:C:\Users\Bert\AutoIt3.My\Temp\test.au3
"C:\Users\Bert\AutoIt3.My\Temp\test.au3"(19,36) : warning: $sLogPath: possibly used before declaration.
            _FileWriteLog($sLogPath,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Users\Bert\AutoIt3.My\Temp\test.au3"(19,36) : error: $sLogPath: undeclared global variable.
            _FileWriteLog($sLogPath,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Users\Bert\AutoIt3.My\Temp\test.au3 - 1 error(s), 1 warning(s)
!>21:47:37 AU3Check ended. Press F4 to jump to next error.rc:2
+>21:47:37 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 1.785

if could compile without error you haben't used Adam's script.

Edited by AutoBert

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