Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Can't delete or replace file in AppleScript

Can't delete or replace file in AppleScript
Thread Tools
Fresh-Faced Recruit
Join Date: Dec 2002
Status: Offline
Reply With Quote
Mar 12, 2003, 10:15 AM
 
I am completely confused here. For some reason my code below would only work when the file needed to be downloaded doesn't exist initially. However when I try running it again (the file being already there) and download the file to a tempfile and replace the old file. It wouldn't replace. Below is my code.

The download is successful but attempting to perform a delete and then rename won't work for some reason.

You can test out my code:

my phoneHome()

on phoneHome()
set iserror to updatePricing("PriceList")
if iserror then
display dialog "Unable to contact server to determine if updated pricing is needed. Will proceed using the most recently downloaded pricing."
else
display dialog "Download complete. Your local price list has been updated."
end if
end phoneHome

on updatePricing(theMarket)
set pricefile to "index.html"
set getFile to "http://www.apple.com/" & pricefile
set tempPath to ("Mac OS Drive:Users:macaroni:Bin:tempfile.txt")
set pricePath to ("Mac OS Drive:Users:macaroni:Bin:pricefile")

try
tell application "URL Access Scripting"
download getFile to file tempPath replacing yes
tell application "Finder"
if file pricePath exists then delete file pricePath
set name of file tempPath to pricefile
end tell
end tell
return false
on error
return true
end try
end updatePricing
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 08:53 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2