Reading and Writing to text files
Reading and Writing to text files
- Subject: Reading and Writing to text files
- From: "Bourque, Jason" <email@hidden>
- Date: Thu, 4 Jan 2001 10:45:18 -0500
Hello,
I have a text file "Log" that 4 to 8 computers read and write to.
This log keeps each computer out of the others way by writing a computer
name and file path for the file that machine is working on and then removing
that entry when it is finished.
i.e.
THIS LOG KEEPS TRACK OF ACTIVE FOLDERS FOR THE MASTER SCRIPT SERVER . . .
Hunch-->MFD-FRMKR-A:Annuity Single Sheets:SS_SunLifeSeriesTrust:PDF
Files:Out:
Crunch-->MFD-FRMKR-A:Bank Trust Single Sheets:SS_BankTrust:PORT_ID_179.fm
Munch-->MFD-FRMKR-A:Bank Trust Single Sheets:SS_BankTrust:PORT_ID_176.fm
This has worked fine until recently I get an error on all of the machines at
once.
"File not open with write permission."
It might be my try statement but I am not sure. I think it is the handler to
remove the log entry.
the code is below any help would be useful
on removeActiveFolderFromLog(folderString)
tell application "Finder"
set computerName to name of startup disk
end tell
set currentActiveFolderLog to "PLATINUM:Scripting:Script Logs:Active Folder
Log"
set resultAttained to false
repeat until resultAttained
try
open for access file currentActiveFolderLog with write
permission
set currentLog to read currentActiveFolderLog as text using
delimiter return
set resultAttained to true
on error
my checkDisks()
activate me
display dialog "Waiting to remove folder from log . . ."
giving up after 5
set resultAttained to false
end try
end repeat
set titleCount to 1
repeat with nth from 1 to count of currentLog
set thisEntry to (contents of item nth of currentLog)
if thisEntry is not (computerName & "-->" & folderString) then
write thisEntry & return to file currentActiveFolderLog
starting at titleCount
set titleCount to titleCount + (count of thisEntry) + 1
end if
end repeat
set eof currentActiveFolderLog to titleCount - 1
close access file currentActiveFolderLog
tell application "Finder"
if folderString ends with ":" then
set thisFolderName to name of folder folderString
else
set folderString to reverse of (every item of folderString)
as string
set folderString to (reverse of (items (offset of ":" in
folderString) thru -1 of folderString)) as string
set thisFolderName to name of folder folderString
end if
try
close window thisFolderName
end try
end tell
return true
end removeActiveFolderFromLog
Jason Bourque
MFS Investment Management