de en es fr
Let the machine help
Light teasing, exhibition, BDSM, sissyfication, watersports... with sounds and pictures


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Copy and rename a file?
PostPosted: Mon Mar 18, 2013 5:09 am 
Offline
Veteran
User avatar
Is this possible from within SexScripts?

What I'd like to do is:
1) Let the user select a file on their hard drive (works)
2) Copy this file to a subfolder in Images (works)
3) Rename the file to "yourPic" (don't know how!)

No problem if it can't be done (there are other workarounds), but I wasn't sure if this was possible or not using groovy.


Top
 Profile Send private message 
 
 Re: Copy and rename a file?
PostPosted: Mon Mar 18, 2013 8:44 pm 
Offline
Site Admin
User avatar
Here are the 3 solutions.
1) Let the user select a file on their hard drive (works)
Code:
def oldName = getFile("Which file ?")

2) Copy this file to a subfolder in Images (works)
Code:
def newName = "images/myscript/"+new File(oldName).getName()
new File(newName) << new File(oldName).getBytes()

3) Rename the file to "yourPic" (don't know how!)
Code:
new File(newName).renameTo("images/myscript/yourPic.jpg")

2+3) but simpler
Code:
new File("images/myscript/yourPic.jpg") << new File(oldName).getBytes()



See also an old message


Top
 Profile Send private message 
 
 Re: Copy and rename a file?
PostPosted: Tue Mar 19, 2013 5:17 am 
Offline
Veteran
User avatar
Thanks, that works great (was doing the first two... love the third 'simpler' option alternative!).

One more thing, though: I notice that I can only make it work 'once'... that is, it won't overwrite the same filename if I run the same script again (have to delete the image manually for it to work again).

Is there a way to let it overwrite the file if it already exists?


Top
 Profile Send private message 
 
 Re: Copy and rename a file?
PostPosted: Tue Mar 19, 2013 9:08 am 
Offline
Site Admin
User avatar
Doing a copy and not a renaming (2 or 2+3) should work.
Or deleting before renaming
Code:
new File(newName).delete


Here is my references, a full page from Groovy : Recipes For File


Top
 Profile Send private message 
 
 Re: Copy and rename a file?
PostPosted: Mon Aug 17, 2015 2:20 pm 
Offline
Site Admin
User avatar
Notice (Android) : when in scripts using some additional java functions to open a file, I recommand from now set the path to an absolute folder explicitely, with this expression : System.getProperty("user.dir").

For example, from :
Code:
new File(newName).renameTo("images/myscript/yourPic.jpg")

To :
Code:
def dir = System.getProperty("user.dir")
new File(dir+"/"+newName).renameTo(dir+"/images/myscript/yourPic.jpg")


Top
 Profile Send private message 
 
 Re: Copy and rename a file?
PostPosted: Sat Jun 16, 2018 7:05 pm 
Offline
Site Admin
User avatar
Notice 2 : since API 9, you should use instead getDataFolder()


Top
 Profile Send private message 
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Maroon Fusion theme created by Oxydo
Software, theme modifications, phpBB modification by Doti 2010 - 2020
This website uses session cookies only.