Jump to content

Remove files from directories


Recommended Posts

I just tested it with 9 in the fileopen statement. I deleted the directory and existing log file. Other then an initial error in setting my path for the log file. I forgot a "\" in the assignment after the ":". The routine worked just great.

Thanks for the clarification on the correct usage of the FileOpen command.

Now looking at the GUI stuff it's a bit more involved then the normal scripting. What would be the best steps to get a handle on it? I looked at the help file for the edit control and opened it in the script editor and ran it. I guess you have to write the code as functions to use the GUI controls. Now at the top of the example code there were calls to functions. I guess I can put in the call the variable holding the path and filename for the log file then call it and have the function read that and populate the edit control with that file.

I made a test file to use the run command to use notepad to display the file and it worked

Run(@WindowsDir & "\notepad.exe " & $logfile, "")

This is what I am going to use till I get a handle on the GUI stuff.

Again thanks for all you time and help. You have been a huge help to my learning this stuff.

Link to comment
Share on other sites

  • Replies 74
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • Moderators

sparker366,

Glad I could help. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Well I figured out the GUI control. Pawing through the help files I looked at the edit control information and copied that to the editor and ran it and saw what it did. I then did some experimenting and came up with this code. Now I do have to apologies but searching the forums and google didn't yield me a lot of examples for this. Now I was wondering do I just add this as code to the end of my script and let it run there or can I make a function in the script and call it in there. Not sure what the best way to do it would be? Everything in the script works the way I want it to work. Maybe folks looking at it can clean it up for me as it may be very primitive.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <File.au3>

Local $logfile = "d:\logs\dellog.log"
Local $myedit

Local $file = FileOpen($logfile, 0)

If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf

; Read the file into the variable
Local $chars = FileRead($file)

;GUI to display the log file

GUICreate("My GUI edit", 600, 600)

$myedit = GUICtrlCreateEdit($chars, 0, 25, 575, 575, $ES_READONLY + $WS_VSCROLL + $WS_HSCROLL)

GUISetState()
Send("{END}")

While 1
$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()
FileClose($file)
Link to comment
Share on other sites

  • Moderators

sparker366,

I made a few changes: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

; Anything in the main script is automatically Global in scope
Global $logfile = "d:\logs\dellog.log"

; No need to open the file first if you use the filename
Local $chars = FileRead($logfile)

; Store the GUI handle
$hGUI = GUICreate("My GUI edit", 600, 600)

; Use BitOR to combine styles
$myedit = GUICtrlCreateEdit($chars, 0, 25, 575, 575, BitOr($ES_READONLY, $WS_VSCROLL, $WS_HSCROLL))

GUISetState()

; Much more precise than just a send
ControlSend($hGUI, "", $myedit, "{END}")

While 1
    ; Slightly shorter syntax
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

But what you had was perfectly sound - if not best practice. Look at the Setting Styles tutorial in the Wiki to see why BitOR is used for combining styles. And the Variables - using Global, Local and ByRef tutorial might be interesting as well. ;)

As to where to put it - just add it at the end of your script then it will run as the deletion code ends. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

The original code was mainly cut and paste from the help file changing things out to what I named them. So I will go through the script and the help file and the links you gave me and read up some more.

Most of the information in the help file is using local to declare variables so I just copied that. I guess the $File variable would be a global one and $chars would be a local. Guess I need to read up more on variable scope some more.

What you referred to "not best practice" was referring to the BITOR omission?

Link to comment
Share on other sites

  • Moderators

sparker366,

I was referring to anything in the script that I changed. What you had worked, but you might as well see how to do it "properly". One of the best ways to learn AutoIt is to look at the code posted by the more experienced members - particularly in the Examples section (some of the snippets we post in the Help sections are very rough and ready). There you will see the proper use of many of the more abstruse things like variable scope. But the main rule is "if it works it works" - so do not feel that you are doing anything particularly wrong - it is just that experience has shown that certain coding practices are better than others. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I see that you removed the #include <File.au3> line. Is that not needed? I thought I read in the help file that you needed that include if you were working on files?

What initially stumped me on the editcontrol was loading it. I thought I could just pass it $logfile and it would read it and load. LOL was I wrong. I just got the the contents of the variable which was path and filename. Then after some more digging I saw the fileread command and that loaded it into a variable and then it was displayed in a msgbox. I then took that concept and put it in place in the editcontrol and it worked. So I am learning to build on concepts and such.

I just wish there was a good book for Autoit. I like reading books and getting my information from them.

Ok this may sound like a weird question but where should I go next? This script is pretty much complete. I know I made a statement about using an ini file. I will look into that and see how to implement it to read in file lists to be processed. I just have to determine what will trigger the using of the ini file lists. The script gets called from an external app that passes it a path. I guess I could use a "StringInStr" to check the path for a certain directory and then can use the ini section for that directory. Again not sure the ini file is worth messing with.

Once again thanks for your time insight and patience with all my questions and mistakes. You are an invaluable source for this community.

Link to comment
Share on other sites

  • Moderators

sparker366,

You only need to #include library files if they contain functions you want to use. Hence you had to include RecFileListToArray.au3 to use the eponymous function within. Usually the functions contained in these libraries begin with an underscore (_) - the functions you were using in your script (FileOpen, FileRead, FileClose) are native to AutoIt and do not need external libraries. :)

Turning to books on AutoIt - there is one around but it is very out-of-date. Have you read this excellent tutorial yet? :huh:

And as to where you go next - that is entirely up to you. I suggest you look at some of the scripts in the Example section and see if any of them inspire you. Modesty forbids me from doing more than suggesting that you might take a look at the various UDFs I have written and which are listed in my sig below - although sometimes a bit complex they are pretty well commented and the examples might offer you some ideas for future projects. But please start a new thread if you do head off into new pastures. Good luck. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Well I am modifying the script to either take a command line parameter for the path or an input box entry for the path. This way I can manually run the script with out opening a cmd prompt window.

I added this code to a simple test file and it worked. I at first thought I could use the IsArray call to see if $cmdline was a valid array but that failed when I tried it. So I came up with this code after googleing.

If $cmdline[0] <> 0 Then
    $path = $cmdline[1]
Else
    $path = InputBox("Folder Path", "Enter The Folder to process.", "")
EndIf

I just ran it and it worked just fine. So this script is now 99.99% complete. Not sure what the .01% that is missing but it works like a champ for what I want. I do have one question is there any way to autosize the gui edit control or do I have to just set a fixed width and height and live with the scroll bars. These paths can be pretty long at times based on different things.

Link to comment
Share on other sites

I need to auto close the gui control that is displayed at the end of the script. If it stays open without closing it delays the calling program from processing the rest of its queue. I can be afk at times when the calling program is running and won't be able to close the control. Now I can try running notepad to display the log and see if that will help but I like using the guicontrol to do it.

Not sure how to do this. Did some searching with google but nothing came up that would help me.

Edited by sparker366
Link to comment
Share on other sites

  • Moderators

sparker366,

I need to auto close the gui control that is displayed at the end of the script

At the moment the GUI will only close when you click on the [X]. What do you mean by "auto-close"? Do you want to close it after a certain time? If so then something like this should do the trick:

; Get a timestamp
$iBegin = TimerInit()

; Run the loop for 10 seconds
While TimerDiff($iBegin) < 10 * 1000
    ; Look for the [X] which will exit immediately
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

; After 10 secs or after the [X] is clicked we get here and the script ends

Will that do? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

sparker366,

What do you think? Have you tried? ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

That worked great took care of the issue replaced the while loop at the end of the gui stuff and it closed after 10 secs and my other app finished processing and moved onto the next queue item.

Yeah I just tried it needed to have some stuff running in the other app lol. I just made that post to make sure is all sure it could have been omitted but I am cautious

Edited by sparker366
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...