Replace an existing file with a new one

This is probably a very simple problem. I have a script that is making an XML document. I am sucking information out of a database and exporting it as a XML file. The script runs just dandy except when I want to update the text file I receive an error along the lines of "the file already exists".
What code do I use to replace an existing file?
tell application "Finder"
set theFile to "donky.xml" as string
set theFullName to mySavePathAsText & theFile
set theNewFile to make new file at myPath with properties {name:theFile}
write myFinalText to file theFullName
set the extension hidden of theNewFile to false
end tell
I assume I would use the "replacing yes" command but that is not working or I am not doing it right.
Any help much appreciated.

Hello
Two things.
• 'open for access file _path with write permission' will create new file at the path given in _path if it's not present.
• 'set eof' command will clear the existing contents of the given file, which lets you replace the contents.
So you may try something like this. (Finder is only used to set 'extension hidden' property of the file)
Good luck
H
-- SNIPPET
set theFileName to "donky.xml"
set theFullPath to mySavePathAsText & theFileName
try
set fref to open for access file theFullPath with write permission
set eof fref to 0 -- clear the existing contents
write myFinalText to fref starting at eof
close access fref
on error errs number errn
try
close access file theFullPath
on error --
end try
error errs number errn
end try
tell application "Finder"
set extension hidden of item theFullPath to false
end tell
-- END OF SNIPPET

Similar Messages

  • Can iTunes convert a file and replace the old file with the new one?

    I am trying to convert my wav files to Apple Lossless to save some space. How can I convert the files and make them replace the old files? Right now it just converts new files so that I end up with two files. I have thousands I want to convert and just replace the old ones.
    I have an external program that will do it for me, however if I go that route then when my ITunes files are converted to lossless files I need to re-link the files as they show up with the ! showing they are missing. That would mean manually re-linking every song, which would take forever unless there is a way to mass re-link all the files.

    iTunes does not see the newly created files as the same file because they are not the same file.  They are new, different files.  If you have a track that is 1234.wav and you create 1234.mp3 it simply isn't the same file and you can't trick iTunes into thinking it is.  iTunes will handle it as a brand new file.
    Check Dougscripts web site for scripts which help modifying tag data.  However, I suspect you won't find any doing exactly what you want doing.  Some tag data are only accessible by iTunes itself.
    As for playlists, there's things you can try though they may be more effort than they are worth.  For example, you could add a special code for each playlist to some element of a tag (e.g., grouping).  Convert the file, then make a smart playlist selecting for the code you added to the group of tracks in the old playlist.  If you have hundreds of playlists with a dozen tracks each this will be a grand nuisance.  If it is a handful of playlists with hundreds of tracks each this might be worth it.
    Another way to preserve playlists would be to edit the .xml copy of the iTunes library file, replacing ".wav" with ".mp3" or whatever format you are using.  However, this won't help with play counts because that is only stored in the .itl copy of the file which you cannot edit.

  • How do I replace my existing HD with a new one

    I have existing drive with my catalogues. I want to use my new 2T WD drive as a replacement for my existing HD which is not working well. Do I clone the original and how do I tell LR 3 to recognize the new drive?  Using Mac Lion.

    By reading the user manual that came w/your router, contacting the manufacturer and/or visit their customer support/troubleshooting website. 

  • Replacing an existeing theme with a new one

    Hello,
    I have an application built that require some new cosmetics. How can I replace the current theme to a new theme without disturbing it's navigation and functionality?
    This is on Apex 32/Oracle 10gxe
    Thanks,
    R

    Hi,
    You can change your application theme
    http://download.oracle.com/docs/cd/E14373_01/appdev.32/e11838/themes.htm#sthref1520
    Or you can edit your theme templates
    http://download.oracle.com/docs/cd/E14373_01/appdev.32/e11838/themes.htm#sthref1547
    Br,Jari

  • How do you replace a time capsule with a newer one

    How do you replace a time capsule with a newer one?

    LOL.. pull the old one out.. put the new one in. Setup the new one.. do not copy setting from the old one.. it is better to start over and never copy configuration files.. although you might get away with it.
    Plug the old TC into the new one.. change it to bridge mode.
    You can then access and copy old backups to the new TC if you want. Although IMHO just keep the old TC for 6months. .then wipe it and sell it or use in different role. Do start clean fresh backups on the new TC.
    If that is all useless. ask the specific question and we can try for a specific answer.

  • I replaced my old iphone with a new one and i lost it i want the s/n of the new one

    i replaced my old iphone with a new one and i got it without the box today my new iphone is stolen and i need the serial number of the new one
    thanks

    Read here for the various ways to locate the SN:
    http://support.apple.com/kb/HT4061

  • I had to replace my Iphone 5c with a new one.  Now, my windows 7 pc does not recognize my iphone.  Reinstalled itunes.  Apple mobile device is running.  I did whatever I could find on the internet still no luck.  Any suggestions?  Thnx

    I had to replace my Iphone 5c with a new one.  Now, my windows 7 pc does not recognize my iphone.  Reinstalled itunes.  Apple mobile device is running.  I did whatever I could find on the internet still no luck.  Any suggestions?  Thnx

    You have done everything verbatim included with this link?
    http://support.apple.com/kb/ts1538

  • HT4889 Replacing System hard drive with a new one. How to get everything over to the new boot drive?

    Replacing System hard drive with a new one. How to get everything over to the new boot drive? Should I use Carbon Copy or does apple have a better untility to do this?
    I can't get my current system drive (OSX 10.8.3) to start on the first try. I always have to shut down and restart again to finally see the Apple logo.
    Have used disc utility to repair the disc and permissions several times and that works. The next time I boot up, it works fine and I get the apple logo, but then the second time I boot up, it's back to the blank screen again and it only boots after the second try.  I have tried this repair three different times now always with the same result. Works right the first try (after the repair) then from the second time on it doesn't work. I just get the white screen until I reboot a second time.
    Thinking I should change drives but what's the easist and best way to move everything over to the new drive so it will boot correctly with all my data on it. This is the system drive for a Pro Tools 10HD setup. MacPro 3,1 with 16 gigs ram and OSX10.8.3 on it.
    Thanks for any help!

    If you have a time machine back up of your current drive you can do this
    Shut down your computer, install the new drive. While the computer is off plug in the external hard drive that you have your time machine back up on. Hold Option key while the computer turnes on, let go of the option key once you get a grey screen. Shortly after you'll see  a list of bootable drives, select the one that has your time machine back up on it and boot into that drive.
    From there go into disk utility, format your new drive too, osx extended journaled ( I think, double check that, its been awhile since ive had to do this), hit format
    Exit disk utility and then you can use time machine to copy all your exisit data to the new hhd and then your pretty much done.
    There is also a program called Carbon Cloner that will do esentially the same thing however I've never uesed it.

  • I downloaded CS6 Red Plug-In and added to Package Contents, replaced the current files with the new without backing up, now my RED footage thumbnails and color-correction don't WORK! How do I get my old importerRed file back!!?? HELP!

    I downloaded CS6 Red Plug-In and added to Package Contents, replaced the current files with the new without backing up, now my RED footage thumbnails and color-correction don't WORK! How do I get my old importerRed file back!!?? HELP!

    Try asking in the Premiere Pro  forum seems to be an Adobe Lab for Premiere Pro

  • Hi how are you i want to replace my iphone 4 with a new one. But i am in Darwin,there is no any apple stores. So where can i send my phone for replacement and how much for that?

    Hi how are you i want to replace my iphone 4 with a new one. But i am in Darwin,there is no any apple stores. So where can i send my phone for replacement and how much for that?

    Warranty and Support are only valid in the country of origin.  You will need to take the device to whatever country it originally came from.
    Apple will not accept shipments from outside the country nor will they return it to an address outside the country.

  • I wanted to know if i were to come into an Apple store, would you be able to replace my home button with the new one that i bring in?

    I wanted to know if i were to come into an Apple store, would you be able to replace my home button with the new one that i bring in?

    Nope, since no one here works for Apple I doubt they would let us behind the counter or use their tools.
    Do a google search to locate your local store and get a phone number-then call and ask.

  • I want to know if there is any possibility to replace my old macbook with a new one and pay a price difference ?

    i want to know if there is any possibility to replace my old macbook with a new one and pay a price difference ? I have a 2008 Macbook that is slowly failing on me and i wanted to know if there is any possibility to bring it to an apple store and swap it with a newer one and pay a small amount of money? If not does anyone have another suggestion how not to pay that much money to buy a new one and/ or maybe seling my old one for some money ?
    Thank you would appreciate any help !

    RockayaAbdel wrote:
    I have a 2008 Macbook that is slowly failing on me and i wanted to know if there is any possibility to bring it to an apple store and swap it with a newer one and pay a small amount of money?
    No.  but you can sell it privately and use the proceeds towards a newer used model.

  • How can I replace an older save file with a new one on game center?

    Greetings,
    I have been trying to change an older game saved file that I have created with my old Ipad with the new one that I have created on my new Ipad, both game files are played under my apple ID but I have no idea how to replace my older one with the new one.
    The new file is superior to the old one so I wish to add the new saved file to my game center.
    The game I am playing is Clash of Clans both file are created on apple products.
    Let me know if there is a sulotion for that case.
    Regards

    Make sure the site folder created by iWeb is named exactly the same as the site folder currently on the server.
    OT

  • If I replace my old iMac with a new one can I burn DVDs on an external drive using Mountain Lion or Toast?

    My 2006 iMac is getting a bit long in the tooth and I was thinking of replacing it with a new one. However, Mac have not included an optical drive and I back up my photographs on DVD as well as external hard drives. I also supply DVDs of my work to friends etc.
    Will I be able to burn to an external drive using Mountain Lion or other software such as Toast? Does the burn option still exist on the new machines?

    Hello,
    You shouldn't have any problem, if you do just try Burn...
    http://burn-osx.sourceforge.net/Pages/English/home.html

  • How can I replace a *.default profile with a new one?

    I had several problems with a laptop being infected with malware. As a result FireFox would not open and thus I couldn't export the bookmarks before reformating the drive. Before reformatting the drive I copied the FireFox files in user/appdata/mozilla/firefox/ both the Local and Roaming subfolders to another drive. I installed FF 4 after the reformat, replaced the *.default files in the new profile with those I saved from the old installation and got the error message " . . all ready running."

    Delete the '''parent.lock''' file, if it exists in that Profile.

Maybe you are looking for

  • How do I set permissions between iMac and Macbook Pro using apple extreme base station hooked up to comcast modem

    I am trying to share files on my iMac with my wife's macbook Pro for which I am set up as a second user with administration privileges.  I think i have the computers finding each other (for example my iMac shows up on the shared list in my wifes's fi

  • Imac freezese an now will not boot up

    I have a 24in imac late 2006 which has recently been difficult to wake up with screen pixilation etc. Now it just freezes as soon as you touch anything and I cannot even get it to boot up now. Have reset smc and pram and now just have a blank screen.

  • BSEG X FB03

    Hello! In BSEG the column u201CPlanned amountu201D have value just for credit postings (without the corresponding debit). Is that correct or should it have postings for both Debit and Credit? Thanks

  • Portforwarding 3389 requests for more than one pc

    I have 2 computers that I want to acces through internet using Remote desktop. On my WRT54G I have forwarded port 3389 to internal ip 10.0.0.100. for the second pc I thought of using port 3390 external to ip 10.0.0.99 3389 internal. I have done so on

  • Issues in Posting_interface_clearing

    Hi All, I am posting a Customer invoice using BAPI_ACC_DOCUMENT_POST and then I am clearing the same by calling the FM, Posting_interface_clearing. In some cases, the Clearing fails with the message that 'Difference is too large for clearing'. Howeve