I have a bug in my code and concerns writing a log file.
I have written it before and it worked but i am now in the process of tidying and deleteing old obsolete code, in the hope to make it faster.
The code snippet that i am having problems on is below:
property logFile : "Shared G4 HD:Users:karrenmay:Desktop:checkFolderAgainstFile:lastRunLog.txt" as alias
property libraryFile : "Shared G4 HD:Users:karrenmay:Desktop:checkFolderAgainstFile:filesUploaded.txt" as alias
property theFolder : "Shared G4 HD:Users:karrenmay:Desktop:web pics:" as alias
property uploadedFolder : "Shared G4 HD:Users:karrenmay:Desktop:checkFolderAgainstFile:uploaded to Net:" as alias
------------------------------------------------------------------------------------------------------------------------
-- ^---- Above sets the global variables
-- v---- Below sets the counters and starts the script
------------------------------------------------------------------------------------------------------------------------
set fileTabber to "1"
set notCount to "0"
set delCount to "0"
------------------------------------------------------------------------------------------------------------------------
-- ^---- Above sets the counters and starts the script
-- v---- Below checks the files against the fileName
------------------------------------------------------------------------------------------------------------------------
--clearTxtFile(logFile)
set fileList to read libraryFile as list using delimiter return
set listCount to count fileList
set folderList to list folder theFolder without invisibles
set folderCount to count folderList
--try
repeat with n from 1 to folderCount
set theItem to item n of folderList as string
if fileList does not contain theItem then
my addToLogFile(logFile, theItem, fileTabber)
set notCount to (notCount + 1)
if fileTabber is equal to 3 then
set fileTabber to 1
else
set fileTabber to (fileTabber + 1)
end if
else
my moveTheFile((theFolder as string) & theItem)
set delCount to (delCount + 1)
end if
end repeat
my appendToFile(logFile, listCount, notCount, delCount)
--on error theError
--end try
------------------------------------------------------------------------------------------------------------------------
-- ^---- Above checks the files against the fileName
-- v---- Below adds the item to the log file
------------------------------------------------------------------------------------------------------------------------
on addToLogFile(theLogFile, theItem, fileTabber)
try
if fileTabber is less than 3 then
open for access theLogFile with write permission
write (theItem & " ") to theLogFile starting at eof
close access theLogFile
else
open for access theLogFile with write permission
write (return & theItem & " ") to theLogFile starting at eof
close access theLogFile
end if
on error theError
display dialog theError
try
close access theLogFile
end try
end try
end addToLogFile
Basically what should happen is this code looks through a folder namely web pics, compares the filenames against the txt file, if its not been uploaded the same filename is then sent to the logFile and if it has been uploaded then it will move the file to the uploaded folder.
The code itself works, it checks against the file and is faster than before, but it doesnt write the log.
Any ideas?