I've tried:
def jobDir = File.createTempFile('sequence_job', new
File('/home/bas/kluthta/cylofold_jobs/'))
jobDir.mkdir()
Any suggestions?
--
View this message in context: http://www.nabble.com/Creating-a-Temporary-Directory-tp24755903p24755903.html
Sent from the groovy - user mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
do I miss something - does this compile ?
--
Andreas Jöcker
GiS - Gesellschaft für integrierte Systemplanung mbH
Junkersstr. 2
69469 Weinheim
E-Mail a.jo...@gis-systemhaus.de
Telefon +49 6201 503-59
Fax +49 6201 503-66
Gesellschaft für integrierte Systemplanung mbH
Geschäftsführer: Eckhard Haffmann, Alfred Gai, Bernd Heselmann
Sitz der Gesellschaft: Zeppelinstr. 11 - 91052 Erlangen
Amtsgericht Fürth/Bayern - Handelsregister-Nr. HRB 3435
~~ Robert.
AwTIn wrote:
> Using *.mkdir() works fine for creating a standard directory, but, even after
> various Internet searches, I can't seem to be able to create a temporary
> directory.
>
> I've tried:
>
> def jobDir = File.createTempFile('sequence_job', new
> File('/home/bas/kluthta/cylofold_jobs/'))
> jobDir.mkdir()
>
> Any suggestions?
>
--
~~ Robert Fischer, Smokejumper IT Consulting.
Enfranchised Mind Blog http://EnfranchisedMind.com/blog
Check out my book, "Grails Persistence with GORM and GSQL"!
http://www.smokejumperit.com/redirect.html
--
View this message in context: http://www.nabble.com/Creating-a-Temporary-Directory-tp24755903p24756001.html
Sent from the groovy - user mailing list archive at Nabble.com.
new File( File.createTempFile(...).parentFile(), 'someDir' ).mkdir()
Although your use of File.createTempFile is odd; that method takes two
strings, (a file name prefix and suffix) -- you're passing a prefix
and a File instance which points to a directory. createTempFile
specifies that the method creates an empty file, so you cannot call
"mkdir()" on the resulting File instance to create it as a directory.
This is very different from new File(..) which just creates a
'descriptor' of sorts, which may or may not represent an actual file
or directory on the filesystem.
-Tom
~~ Robert.
Andreas Jöcker wrote:
>> def jobDir = File.createTempFile('sequence_job', new
>> File('/home/bas/kluthta/cylofold_jobs/'))
>> jobDir.mkdir()
>>
>>
> you are using a wrong method call... createTempFile either takes two
> Strings (prefix / suffix) or two Strings + a File object (the temp
> directory).
>
> do I miss something - does this compile ?
>
>
--
~~ Robert Fischer, Smokejumper IT Consulting.
Enfranchised Mind Blog http://EnfranchisedMind.com/blog
Check out my book, "Grails Persistence with GORM and GSQL"!
http://www.smokejumperit.com/redirect.html
---------------------------------------------------------------------
afaik groovy doesnt offer any additional File.createTempFile construct
(at least not shown in the docs) - and your construct is not java correct !
def jobDir = File.createTempFile('sequence_job', '.temp', new
File('/home/bas/kluthta/cylofold_jobs/'))
jobDir.mkdir()
would fit
--
View this message in context: http://www.nabble.com/Creating-a-Temporary-Directory-tp24755903p24756337.html
--
View this message in context: http://www.nabble.com/Creating-a-Temporary-Directory-tp24755903p24756351.html
Sent from the groovy - user mailing list archive at Nabble.com.
but now its aleast a correct syntax....
> Sorry, I am rather new to Groovy (and Java, for that matter0. What exactly
> do you mean by ".parentFile()"?
http://java.sun.com/javase/6/docs/api/java/io/File.html#getParentFile()
--
Andreas Jöcker
GiS - Gesellschaft für integrierte Systemplanung mbH
Junkersstr. 2
69469 Weinheim
E-Mail a.jo...@gis-systemhaus.de
Telefon +49 6201 503-59
Fax +49 6201 503-66
Gesellschaft für integrierte Systemplanung mbH
Geschäftsführer: Eckhard Haffmann, Alfred Gai, Bernd Heselmann
Sitz der Gesellschaft: Zeppelinstr. 11 - 91052 Erlangen
Amtsgericht Fürth/Bayern - Handelsregister-Nr. HRB 3435
new File( File.createTempFile('sequence_job',
'.dir').parentFile(), '/home/bas/kluthta/cylofold_jobs/' ).mkdir()
I am getting a runtime exception after compilation. Am I missing something?
--
View this message in context: http://www.nabble.com/Creating-a-Temporary-Directory-tp24755903p24756580.html
Take a more careful read-through of the java.io.File API: you're not quite grokking how it works.
~~ Robert.
--
~~ Robert Fischer, Smokejumper IT Consulting.
Enfranchised Mind Blog http://EnfranchisedMind.com/blog
Check out my book, "Grails Persistence with GORM and GSQL"!
http://www.smokejumperit.com/redirect.html
---------------------------------------------------------------------
Also, if you're trying to create a temp dir in the given dir you're
listing as the second argument, you probably want a different
approach. As someone else mentioned, you probably want to create the
unique temp file, then delete it and re-create as a directory. So do
like this:
File baseDir = new File( '/home/bas/kluthta/cylofold_jobs/' )
File dir = File.createTempFile( 'sequence_job', '.dir', baseDir )
dir.delete() // delete the file that was created
dir.mkdir() // create a directory in its place.
import org.springframework.web.util.WebUtils
import org.codehaus.groovy.grails.web.context.ServletContextHolder
import grails.util.BuildSettingsHolder
def tmp = ServletContextHolder.servletContext ?
WebUtils.getTempDir(ServletContextHolder.servletContext) :
BuildSettingsHolder.settings.projectWorkDir
ServletContextHolder.servletContext is null during tests.