|
Hi,
Based on https://jira.codehaus.org/browse/GROOVY-4990 I'd like to propose a new DGM for java.io.File: def f = new File('/some/dir/subdir/subsubdir/file.txt') f.mkParentDirs().write('test') mkParentDirs() will recursively create all non-existent parent directories. In the example above, if /some/dir would exist, it would create subdir/subsubdir/. If the parent path exists/has been created successfully or no path has been specified, mkParentDirs() returns the actual java.io.File instance. If not, an IOException is thrown. Opinions? Suggestions? Cheers, André |
|
Would an overloaded static File mkdirs( File self, boolean parents ) Be better than introducing a new method name? The functionality would be really useful though... Encountered a need for it only today! Tim On 22 Feb 2012 21:04, "Andre Steingress" <[hidden email]> wrote:
Hi, |
What do others think? If parents == true we would need something like self.exists() || self.getParentFile() == null || self.getParentFile().exists() || self.getParentFile().mkdirs() else we would default to self.mkdirs(). Cheers, André |
|
In reply to this post by tim yates-2
On 02/22/2012 10:35 PM, Tim Yates wrote:
> > Would an overloaded > > static File mkdirs( File self, boolean parents ) > > Be better than introducing a new method name? > > The functionality would be really useful though... Encountered a need > for it only today! > > Tim > http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#createDirectories%28java.nio.file.Path,%20java.nio.file.attribute.FileAttribute...%29 Rémi > On 22 Feb 2012 21:04, "Andre Steingress" <[hidden email] > <mailto:[hidden email]>> wrote: > > Hi, > > Based on > > https://jira.codehaus.org/browse/GROOVY-4990 > > I'd like to propose a new DGM for java.io.File: > > def f = new File('/some/dir/subdir/subsubdir/file.txt') > f.mkParentDirs().write('test') > > mkParentDirs() will recursively create all non-existent parent > directories. > In the example above, if /some/dir would exist, it would create > subdir/subsubdir/. If the parent path exists/has been created > successfully > or no path has been specified, mkParentDirs() returns the actual > java.io.File instance. If not, an IOException is thrown. > > Opinions? Suggestions? > > Cheers, André > > -- > View this message in context: > http://groovy.329449.n5.nabble.com/DGM-proposal-File-mkParentDirs-tp5506254p5506254.html > Sent from the groovy - dev mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
Think we have to currently stick to java 5 as the lowest common version On 22 Feb 2012 21:47, "Rémi Forax" <[hidden email]> wrote:
On 02/22/2012 10:35 PM, Tim Yates wrote: |
|
In reply to this post by Andre Steingress
Should be able to use: if( parent ) { But that is just code typed into my phone whilst Sat print off the tv, and not checked in any way whatsoever ;-) On 22 Feb 2012 21:47, "Andre Steingress" <[hidden email]> wrote:
|
|
'Sat print off' == 'sat in front of' Stupid phone... On 22 Feb 2012 22:03, "Tim Yates" <[hidden email]> wrote: |
|
In reply to this post by tim yates-2
The only issue I see with overloading java.io.File.mkdirs() are the return types. If we choose mkdirs() as the method name, than mkdirs() and mkdirs(true/false) will have different return types: def f = new File('/some/dir/subdir/subsubdir/file.txt') f.mkdirs() // return true/false f.mkdirs(false) // returns f Cheers, André |
|
True... I'll see if I can think of an already existing president for doing this If not, maybe something snappier like mkpath could be used I quite like the idea of being able to make a path and having the function return the file rather than the current boolean Tim On 22 Feb 2012 22:14, "Andre Steingress" <[hidden email]> wrote:
|
A snappier (but slightly more geekier) name than 'mkParentDirs' would be 'mkdirsp'. On the one hand referring to File.mkdirs(), on the other to "mkdir -p". Besides the name, would this DGM be seen as reasonable by the other Groovy devs? Cheers, André |
|
In reply to this post by tim yates-2
On 02/22/2012 10:56 PM, Tim Yates wrote:
> > Think we have to currently stick to java 5 as the lowest common version > As I understand, Groovy 2.0 will come with 2 jars, one compatible with Java 7 and one compatible with Java 5. So I don't see the interest to add a new DGM to Groovy 2.0 if you have a better API in Java 7. java.nio.file is definitively a better and more efficient API than java.io which just shows it's age. Rémi > On 22 Feb 2012 21:47, "Rémi Forax" <[hidden email] > <mailto:[hidden email]>> wrote: > > On 02/22/2012 10:35 PM, Tim Yates wrote: > > > Would an overloaded > > static File mkdirs( File self, boolean parents ) > > Be better than introducing a new method name? > > The functionality would be really useful though... Encountered > a need for it only today! > > Tim > > > http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#createDirectories%28java.nio.file.Path,%20java.nio.file.attribute.FileAttribute...%29 > > Rémi > > On 22 Feb 2012 21:04, "Andre Steingress" > <[hidden email] <mailto:[hidden email]> > <mailto:[hidden email] > <mailto:[hidden email]>>> wrote: > > Hi, > > Based on > > https://jira.codehaus.org/browse/GROOVY-4990 > > I'd like to propose a new DGM for java.io.File: > > def f = new File('/some/dir/subdir/subsubdir/file.txt') > f.mkParentDirs().write('test') > > mkParentDirs() will recursively create all non-existent parent > directories. > In the example above, if /some/dir would exist, it would create > subdir/subsubdir/. If the parent path exists/has been created > successfully > or no path has been specified, mkParentDirs() returns the > actual > java.io.File instance. If not, an IOException is thrown. > > Opinions? Suggestions? > > Cheers, André > > -- > View this message in context: > http://groovy.329449.n5.nabble.com/DGM-proposal-File-mkParentDirs-tp5506254p5506254.html > Sent from the groovy - dev mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
Rémi,
from what I saw, java.nio.file is definitely a cool API and it will instantly solve other issues like for example https://jira.codehaus.org/browse/GROOVY-4879 (Add createTempDir() to File) with http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#createTempDirectory(java.nio.file.Path,%20java.lang.String,%20java.nio.file.attribute.FileAttribute...) yay! I don't not know what's in the pipe for Groovy 2.0 in terms of 5.0/6.0 support and corresponding DGMs - maybe someone could clarify this issue. Cheers, André |
| Powered by Nabble | Edit this page |
