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


Post new topic Reply to topic  [ 10 posts ] 
Author Message
 GetFile and filename extensions
PostPosted: Mon Oct 21, 2013 7:08 am 
Offline
Shy
While waiting for my issue with missing posts to be resolved...

How would I use getFile without grabbing (or removing) the file's extension?

Example:
Code:
def load_script = getFile("Select a .groovy file");

...allows me to select a file. However...
Code:
return ""+load_script+""

... won't work because getfile understandably fetches the full name of the file selected, including the extension (eg. "intro.groovy"). Thus:
Code:
return "intro.groovy"

... is called and (logically) fails.
I fixed the extension problem by first calling:
Code:
load_script = load_script.replace(".groovy", "");

but it seems that it's still trying to return the full path rather than just the file name.

So how do I get "intro" from the user picking the file rather than "C:\Programs\SexScripts\Scripts\intro.groovy"?

Not sure what the best approach is, let alone how to do it, so help would be appreciated by those more skilled in Groovy/Java than I am! :)


Top
 Profile Send private message 
 
 Re: GetFile and filename extensions
PostPosted: Mon Oct 21, 2013 3:46 pm 
Offline
Site Admin
User avatar
The first part of the solution is good. For the beginning, there are a lot of functions for strings, see the official doc. of Groovy.

I'll do this :
Code:
load_script = load_script.replace(".groovy", "")
if(load_script.contains("\\"))
  load_script = load_script.substring(load_script.lastIndexOf("\\"));
if(load_script.contains("/"))
  load_script = load_script.substring(load_script.lastIndexOf("/"));


Top
 Profile Send private message 
 
 Re: GetFile and filename extensions
PostPosted: Mon Oct 21, 2013 4:10 pm 
Offline
Veteran
User avatar
doti wrote:
The first part of the solution is good. For the beginning, there are a lot of functions for strings, see the official doc. of Groovy.

I'll do this :
Code:
load_script = load_script.replace(".groovy", "")
if(load_script.contains("\\"))
  load_script = load_script.substring(load_script.lastIndexOf("\\"));
if(load_script.contains("/"))
  load_script = load_script.substring(load_script.lastIndexOf("/"));


Awesome! Thanks, mate! That did the trick (I'd spent two hours trying to figure out last.IndexOf from random "help" posts online!) :)

Okay, one more question in regard to this: is there a way to specify a "working folder" with:
Code:
def load_script = getFile("Select a .groovy file");

? As in, when it asks the user for a file, the file browser starts off in your "SexScripts/scripts" folder (by default, it seems to open in "My Documents")? I'm pretty sure I can get the path with something like:
Code:
def sscriptDir = new File(".").absolutePath;

but that might not be useful, since I don't know how I'd use that with getFile! :oops:


Top
 Profile Send private message 
 
 Re: GetFile and filename extensions
PostPosted: Mon Oct 21, 2013 7:43 pm 
Offline
Site Admin
User avatar
getFile() is not really customizable, no. It's already quite tricky as it is (inside SS main source code).


Top
 Profile Send private message 
 
 Re: GetFile and filename extensions
PostPosted: Tue Oct 22, 2013 6:39 pm 
Offline
Veteran
User avatar
doti wrote:
getFile() is not really customizable, no. It's already quite tricky as it is (inside SS main source code).

Darn. Understandable (since it's not "your" code to fix) but a pain... having to navigate through two dozen folders just to reach SexScripts is painful! :)

Is there any way/chance a script command to "open file" could be added to SexScripts? By that, I mean something that could be put in a script that triggers the "open file" option from the menu (since that DOES start in the user's SexScripts/scripts folder)?

I'm really wanting a way to totally bypass the standard toolbar/open file menu, you see, and have it all script controlled ("Mistress, may I open a script?" etc.).


Top
 Profile Send private message 
 
 Re: GetFile and filename extensions
PostPosted: Tue Oct 22, 2013 7:50 pm 
Offline
Site Admin
User avatar
As it works in the user space, your SS folder should be next (inside ?) your user folder (that is, ".../my documents/" on a PC with english Windows).

(To architects : I know that it may not be best practice from SexScripts, but it's a compromise)


Top
 Profile Send private message 
 
 Re: GetFile and filename extensions
PostPosted: Tue Oct 22, 2013 8:28 pm 
Offline
Veteran
User avatar
doti wrote:
As it works in the user space, your SS folder should be next (inside ?) your user folder (that is, ".../my documents/" on a PC with english Windows).

(To architects : I know that it may not be best practice from SexScripts, but it's a compromise)

I can see how that would help with getFile, but like a lot of folks, I don't really use "My Documents" at all unless a program forces me to keep things like savegames there (I store files like music, etc. on external or drives other than C:\ for space reasons). Yeah, most installers try to put themselves in "Program Files", but when it comes to those without installers (portable "unzip and run" programs, like SexScripts), "Program Files" is usually not a good idea due to Windows Vista and upwards having screwy ideas of "protecting" things in that folder.


Top
 Profile Send private message 
 
 Re: GetFile and filename extensions
PostPosted: Thu Dec 10, 2015 5:37 am 
Offline
Veteran
User avatar
Bump to see if anyone else knows if there's a way to do this, as it's driving me nuts!

I have
Code:
def sscriptDir = new File(".").absolutePath;

and
Code:
def load_script = getFile("Select a .groovy file");

in my script, but I need to use sscriptDir as the directory "getFile" opens when the file browser opens, rather than defaulting to the "My Documents" folder (or whatever it does on Linux).


Top
 Profile Send private message 
 
 Re: GetFile and filename extensions
PostPosted: Thu Dec 10, 2015 12:48 pm 
Offline
Site Admin
User avatar
There's currently no way to do this.


Top
 Profile Send private message 
 
 Re: GetFile and filename extensions
PostPosted: Fri Dec 11, 2015 9:25 am 
Offline
Veteran
User avatar
doti wrote:
There's currently no way to do this.

Thanks for the reply. Hopefully, along with the repeating sound/music issue, this might be able to be solved in the future.


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

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 5 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.