Sign in to follow this  
Followers 0
deef99

FileDelete not working - what am I doing wrong?

6 posts in this topic

And I thought this was the simplest part of coding this script!

Everything in this script works great...except it will not delete each file once it is done getting the array info. The problem area is towards the end of the code. I've tried putting it different places in the script and it just will not delete the files.

Where am I going wrong???

:)

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****

#AutoIt3Wrapper_outfile=G:\CMS_IBAuto\Monitor\SLMonitor.exe

#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include "array.au3"

#include "File.au3"

#include "Date.au3"

#include "String.au3"

$iIndex = 0

Dim $sl

Dim $read

$pday = ""

$ptime = ""

$y = ""

$agent = ""

$message = ""

$message1 = ""

$skill = 400

$mcount = 0

; Change DIR and process files just moved

FileChangeDir("\\ardfiles01\common\CMS_IBAuto\Monitor")

;look for first occurance of a file

$search = FileFindFirstFile("CMS*.acsup")

While @HOUR > 5

While 1

;look for additional files

$file = FileFindNextFile($search)

If @error Then ExitLoop

$file1 = FileOpen($file, 0)

$agent = StringRight($file, 13)

$agent = StringLeft($agent, 7)

$ptime = StringMid($file, 4, 8)

$pday = StringLeft($ptime, 4)

$pday = StringLeft($pday, 2) & "/" & StringRight($pday, 2)

$ptime = StringRight($ptime, 4)

$ptime = StringLeft($ptime, 2) & ":" & StringRight($ptime, 2)

$read = _FileReadToArray("\\ardfiles01\common\CMS_IBAuto\Monitor\" & $file, $sl)

While $skill <> 403

$iIndex = _ArraySearch($sl, $skill, 0, 0, 0, 1)

If @error Then ExitLoop

$iIndex = $iIndex + 1

$y = StringRight($sl[$iIndex], 2)

If $y = "51" Then

$y = "R1"

ElseIf $y = "52" Then

$y = "R2"

EndIf

If $mcount < 10 Then

$message = $pday & " " & $ptime & " AGENT: " & $agent & " Skill: " & $skill & " Level: " & $y

$message1 = $message & @LF & $message1

Else

$message1 = $message & @LF

$mcount = 0

EndIf

$mcount = $mcount + 1

$skill = $skill + 1

SplashTextOn("SL Automate Monitor", $message1, 350, 190, 800, 75, 20, "", 10)

Sleep(200)

WEnd

$skill = 400

FileClose($file)

; NONE OF THESE WORK!!!!

FileDelete("\\ardfiles01\common\CMS_IBAuto\Monitor\" & $file)

FileDelete("\\ardfiles01\common\CMS_IBAuto\Monitor" & $file)

FileDelete($file)

WEnd

FileClose($search)

WEnd

Share this post


Link to post
Share on other sites



deef99,

You are mixing up $file and $file1. Try using the latter in your FileDelete lines. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

deef99,

You are mixing up $file and $file1. Try using the latter in your FileDelete lines. :)

M23

Lots of things wrong with the usage:
; ...

$file = FileFindNextFile($search)

; ...

$file1 = FileOpen($file, 0)

; ...

$read = _FileReadToArray("\\ardfiles01\common\CMS_IBAuto\Monitor\" & $file, $sl)

; ...

FileClose($file)

; NONE OF THESE WORK!!!!
FileDelete("\\ardfiles01\common\CMS_IBAuto\Monitor\" & $file)
FileDelete("\\ardfiles01\common\CMS_IBAuto\Monitor" & $file)
FileDelete($file)

The variable $file is the string name, and $file1 is the handle from FileOpen().

_FileReadToArray() should have been done with the $file1 handle because it was already open.

FileClose() should have been done with the $file1 handle.

FileDelete() fails because the file is not closed yet.

Lesson: Don't mix usage of a file handle and the string path of the same file.

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Mannnnnnnnnnnnnnnnnnnnn!!!!!! I KNEW it was gonna be something pretty stupid. And look at you two - so kind about it. Hah, you made my day!

Many thanks!

D :)

Share this post


Link to post
Share on other sites

deef99,

Could I suggest using identifiers for your variables along these lines (taken from the UDF rules):

Variable Names
The first set of characters after the dollar sign (“$”) should be used to specify the type of data that will be held in it. The following list signifies the different prefixes and their data type significance. 
$a<letter> - Array (the following letter describes the data type taken from the rest of the data types below) 
$b - Binary data 
$h - File or window handle 
$i - Integer 
$f - Boolean 
$n - Floating point number 
$s - String 
$v - Variant (unknown/variable type of data)
The rest of the name uses capitalized words to describe the function of the variable. Names like “$iC” are unacceptable. "$aiWeekDayNames" or "$iCounter" are much preferable

It really does help you a lot. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

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