changing file name

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
dhobbs
Posts: 24
Joined: Tue Dec 15, 2009 6:25 pm

changing file name

Post by dhobbs » Wed Jul 14, 2010 5:15 pm

Hi, I have an image control that I load from a file on disk. I would like to change the name of the image, and have it change the name of the file on disk. Is there an easy way to do this?
Thanks,

--Doug

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: changing file name

Post by Klaus » Wed Jul 14, 2010 6:06 pm

Hi Doug,

you can:

Code: Select all

...
set the name of img "Old name of your image" to "New name of your image"
...
To rename an image inside of your stack.

Use the "rename" command to rename the image (or any file) on disk:

Code: Select all

...
rename file "/Users/klaus/Desktop/jigsawtest.jpg" to "/Users/klaus/Desktop/a completetely new name.jpg"
...
Best

Klaus

dhobbs
Posts: 24
Joined: Tue Dec 15, 2009 6:25 pm

Re: changing file name

Post by dhobbs » Mon Jul 19, 2010 2:28 pm

Thanks Klaus,
Works great. My rename code now looks like:

Code: Select all

on mouseUp
   put the fileName of image "image" into tOldName
   set itemDelimiter to "."
   put tOldName into tNewName
   ask "New Name:"
   put it into item 1 of tNewName
   rename file tOldName to (defaultFolder & "\" & tNewName)
   send "openstack" to stack "ImageBrowser"  ##refresh list of file names
end mouseUp
Just thought I'd post this in case anyone else wants a snippet to do a similar thing.

Thanks again,

--Doug

Post Reply