Jump to content

Delete all files in a folder


Go to solution Solved by mustilem23,

Recommended Posts

Posted

 

Hello, I am very new and inexperienced in autoit coding, I am trying to progress with the information I received from you. I have a few issues that I am stuck on in a scenario. I want to delete all the pdf, excel or word files in C:\Users\mdogru\Desktop\IFS OUTPUT because I will save different files in this folder later in the scenario .

 

My scenario in the design phase

#include <AutoItConstants.au3>
Func _WinWaitActivate($title,$text,$timeout=0)
   WinWait($title,$text,$timeout)
   If Not WinActive($title,$text) Then WinActivate($title,$text)
   WinWaitActive($title,$text,$timeout)
EndFunc

Opt('TrayIconDebug', 1)
   Opt("WinTitleMatchMode", 2)
   _WinWaitActivate("Satis Teklifi ","")
   Local $sText = WinGetTitle("[ACTIVE]")
   $sText=StringMid($sText,17,9)
;Sorgulama ekranı getiriliyor.

   sleep(1000)

MouseClick($MOUSE_CLICK_LEFT,181 , 120, 2)
sleep(1000)
   ;1 veri kopyalanıyor ,1. copy to the subject okkkkk...
   Send("^C")
   sleep(500)
MouseClick($MOUSE_CLICK_LEFT,1122 , 247, 1)
sleep(500)
MouseClick($MOUSE_CLICK_RIGHT,1122 , 247, 1)
sleep(500)
 send("{TAB 5}")
sleep(50)
Send("{ENTER}")
sleep(500)
_WinWaitActivate("Hızlı Rapor Sorgusu: 015 - SSH Teklif - IFS Applications","")
  sleep(500)
send("{TAB 5}")
  Send("{ENTER}")
;teklif pdf ı görselı
sleep(500)
_WinWaitActivate("015 - SSH Teklif ","")
sleep(500)
MouseClick($MOUSE_CLICK_LEFT,67 , 98, 1)
sleep(500)

 _WinWaitActivate("Export Report","")

  sleep(500)
 send("{TAB 6}")
  sleep(500)
Send("^+{ENTER}")
   sleep(50)
;bu bölgede kaldik
  Send("C:\Users\mdogru\Desktop\IFS ÇIKTILARI")
    sleep(50)
Send("^+{ENTER}")
sleep(50)

 send("^+{TAB 7}")
  Send("^V")
   sleep(50)
Send("{SPACE 2}")
sleep(50)
Send("DURMAZLAR_TEKLIF")
    sleep(50)
send("{TAB}")
   sleep(50)
   Send("^{RIGHT}")
   Send("^{DOWN}")
  Send("{ENTER}")
   sleep(50)
    send("{TAB 2}")
     sleep(50)
Send("^+{ENTER}")
 sleep(2500)
_WinWaitActivate("Export Report","")
  Send("{ENTER}")
;cıktıyı bilgisayarda ki klasore ekleyen bölge son

;BURADA KALDIK

MouseClick($MOUSE_CLICK_LEFT,677 , 419, 1)
 sleep(500)
Send("{ENTER}")
sleep(1000)


MouseClick($MOUSE_CLICK_LEFT,25 , 44, 1)
sleep(50)
 _WinWaitActivate("Satis Teklifi -","")
sleep(50)


MouseClick($MOUSE_CLICK_LEFT,181 , 120, 2)
sleep(2000)
   ;1 veri kopyalanıyor ,1. copy to the subject okkkkk...
   Send("^C")
   sleep(500)



_WinWaitActivate("Durma SSH ve diğer ","")

;TİCKET EKRANINDA KONU İÇİNE BASIYOR


sleep(500)
MouseClick($MOUSE_CLICK_LEFT,297, 160, 1)
sleep(500)




send("{TAB 18}")

 sleep(500)
  Send("^V")
   sleep(500)
Send("{ENTER}") ;SSSSS
   sleep(1500)
MouseClick($MOUSE_CLICK_LEFT,423, 627, 1)
sleep(2000)
   _WinWaitActivate("Aç","")
sleep(1500)
MouseClick($MOUSE_CLICK_LEFT,313 , 49, 1)
  sleep(1500)
Send("C:\Users\mdogru\Desktop\IFS ÇIKTILARI")
 sleep(1500)
 Send("{ENTER}")
  sleep(1000)
MouseClick($MOUSE_CLICK_LEFT,527 , 299, 1)
 sleep(1500)


 Send("^a")

sleep(1000)
Send("{ENTER}")

  sleep(500)
MouseClick($MOUSE_CLICK_LEFT,483 , 172, 1)

sleep(500)
MouseClick($MOUSE_CLICK_LEFT,483 , 172, 2)
sleep(500)
MouseClick($MOUSE_CLICK_LEFT,483 , 172, 1)
sleep(500)
 sleep(500)
  Send("^V")
Send("{SPACE 2}")
sleep(500)
Send("{ENTER}")
sleep(500)
MouseClick($MOUSE_CLICK_LEFT,423, 627, 1)
sleep(500)
;SON EKLEME
sleep(2000)
   _WinWaitActivate("Aç","")
sleep(1500)
MouseClick($MOUSE_CLICK_LEFT,313 , 49, 1)
  sleep(1500)
Send("C:\Users\mdogru\Desktop\IFS ÇIKTILARI")
 sleep(500)
 Send("{ENTER}")
  sleep(500)
MouseClick($MOUSE_CLICK_LEFT,527 , 299, 1)
 sleep(1500)


 Send("^a")
sleep(500)
Send("{DELETE}")
sleep(50)
Send("{ENTER}")
sleep(50)
Send("{ESC}")

 

Posted

Check in help file FileDelete(). You can use wildcards in the path like <DirPath>\*.pdf  in order to delete all pdf files from a directory (replace <DirPath> with the full path to your actually directory).

Posted

Thank you, I have looked through the help file extensively and finally added my folder path to the scenario below, but the files are still there. Can you please help me?

 

#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

Example()

Func Example()
    ; Create a constant variable in Local scope of the filepath that will be read/written to.
    Local Const $sFilePath = _WinAPI_GetTempFileName(@TempDir)

    ; Create a temporary file to read data from.
    If Not FileWrite($sFilePath, "This is an example of using FileDelete.") Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.")
        Return False
    EndIf

    ; Display the contents of the file passing the filepath to FileRead instead of a handle returned by FileOpen.
    MsgBox($MB_SYSTEMMODAL, "", "Contents of the file:" & @CRLF & FileRead($sFilePath))

    ; Delete the temporary file.
    ;Local $iDelete = FileDelete($sFilePath[$i] & "C:\Users\mdogru\Desktop\IFS ÇIKTILARI\*pdf*")
    Local $iDelete ="C:\Users\mdogru\Desktop\IFS ÇIKTILARI\*.pdf*"

    ;Local $masterEdlFile = "G:\Session_Master\Show\Session_Data\Type2.edl"

        FileDelete($_sSrcPath2[$i] & "C:\Users\mdogru\Desktop\IFS ÇIKTILARI\*.pdf*")

    ; Display a message of whether the file was deleted.
    If $iDelete Then
        MsgBox($MB_SYSTEMMODAL, "", "The file was successfuly deleted.")
    Else
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst deleting the file.")
    EndIf
EndFunc   ;==>Example

 

Posted
40 minutes ago, mustilem23 said:
FileDelete($_sSrcPath2[$i] & "C:\Users\mdogru\Desktop\IFS ÇIKTILARI\*.pdf*")

What is $_sSrcPath2? The following path already looks fine.

Posted

 


I think I added it while trying it out. It doesn't matter to me. How can I edit my path according to this scenario? :) I think I made a very small mistake. Can you help me please?

Posted
4 hours ago, mustilem23 said:

I think I added it while trying it out. It doesn't matter to me.

It matters for the script. If it's anything else than empty string or some sort of spaces then most likely you pass to FileDelete() an invalid path.

Posted

Hello Andreik ,
I think you understand me, I am new to coding, can you help me with editing the deletion codes of the files in the folder?
The address of the folder on my computer is this.
C:\Users\mdogru\Desktop\IFS OUTPUTS

Posted
19 hours ago, mustilem23 said:
; Delete the temporary file.
    ;Local $iDelete = FileDelete($sFilePath[$i] & "C:\Users\mdogru\Desktop\IFS ÇIKTILARI\*pdf*")
    Local $iDelete ="C:\Users\mdogru\Desktop\IFS ÇIKTILARI\*.pdf*"

    ;Local $masterEdlFile = "G:\Session_Master\Show\Session_Data\Type2.edl"

        FileDelete($_sSrcPath2[$i] & "C:\Users\mdogru\Desktop\IFS ÇIKTILARI\*.pdf*")
  1. When you don't know something, the best place to start is the local help file of autoit.
     
  2. In your code you have FileDelete($_sSrcPath2[$i] & "C:\Users\mdogru\Desktop\IFS ÇIKTILARI\*.pdf*")  ???
    The path of the files to be deleted, does not make sense.
    and not only because it has a variable ($_sSrcPath2[$i]) that you do not define anywhere in this script
    but also according to the existing path  "C:\Users\mdogru\Desktop\IFS ÇIKTILARI\*.pdf*")
    since the path starts with 'C:\' it could not have anything in front of 'C:\' ,  so   'something' & 'C:\'  make no sense
     
  3. according to help file 'See FileFindFirstFile() for a discussion about wildcards.'
    You can use only one wildcard in the filename part or in the extension part i.e. a*.b?.
    When using a 3-char extension any extension starting with those 3 chars will match, .e.g. "*.log" will match "test.log_1".
     
  4. According to your case, it would fit something like this.

FileDelete ("C:\Users\mdogru\Desktop\IFS OUTPUTS \*.pdf")

I know that I know nothing

Posted

 

 

ioa747 Thank you for your interest. But I couldn't succeed. I copied the help file and added the name of the folder on my computer, but it still didn't delete the pdf files. Could you please check if the coding in this help file is valid?

 

#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

Example()

Func Example()
    ; Create a constant variable in Local scope of the filepath that will be read/written to.
    Local Const $sFilePath = _WinAPI_GetTempFileName(@TempDir)

    ; Create a temporary file to read data from.
    If Not FileWrite($sFilePath, "This is an example of using FileDelete.") Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.")
        Return False
    EndIf

    ; Display the contents of the file passing the filepath to FileRead instead of a handle returned by FileOpen.
    MsgBox($MB_SYSTEMMODAL, "", "Contents of the file:" & @CRLF & FileRead($sFilePath))

    ; Delete the temporary file.
    ;Local $iDelete = FileDelete($sFilePath)
    FileDelete ("C:\Users\mdogru\Desktop\IFS ÇIKTILARI\*.pdf")


    ; Display a message of whether the file was deleted.
    If $iDelete Then
        MsgBox($MB_SYSTEMMODAL, "", "The file was successfuly deleted.")
    Else
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst deleting the file.")
    EndIf
EndFunc   ;==>Example

 

Posted (edited)
2 hours ago, mustilem23 said:

Could you please check if the coding in this help file is valid?

The help is ok - Your code is NOT valid.

The file will be created in $sFilePath but you try to delete .pdf files in "C:\Users\mdogru\Desktop\IFS ÇIKTILARI\"

Take a look at the example for the function https://www.autoitscript.com/autoit3/docs/functions/FileFindFirstFile.htm . You can use it to check whether *.pdf files exist in the directory you have specified. If not, a delete can not be successful.

Edited by Musashi
Answer extended

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Posted

BTW, your last script shouldn't even run since you commented out the declaration of $iDelete.  Always run your script from Scite when you are creating a script, only when you are absolutely sure there is no issue, you can compile or run it from Explorer.

Posted

Hello ,

Thank you all very much but I am very new, can you please send me the codes that can delete a .pdf or all the files in that folder on your computer.

:) I am literally deleting by entering coordinates right now :(

 

_WinWaitActivate("Aç","")
sleep(1500)
MouseClick($MOUSE_CLICK_LEFT,313 , 49, 1)
  sleep(1500)
Send("C:\Users\mdogru\Desktop\IFS ÇIKTILARI")
 sleep(500)
 Send("{ENTER}")
  sleep(500)
MouseClick($MOUSE_CLICK_LEFT,527 , 299, 1)
sleep(1500)
Send("^a")
sleep(500)
Send("{DELETE}")
sleep(50)
Send("{ENTER}")
sleep(50)
Send("{ESC}")

 

  • Solution
Posted
 

I changed my perspective and it was solved :) How about moving it to the trash instead of deleting it? I think deleting it requires administrator permissions in Windows.

;ilgili yoldaki daha önceki tüm dosyaları siliyor.
FileRecycle ( "C:\Users\mdogru\Desktop\IFS ÇIKTILARI\*.*")

 

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