Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions docs/reference/stdlib-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -691,9 +691,6 @@ The following methods are available for manipulating files and directories in a
`getPermissions() -> String`
: Returns a file's permissions using the [symbolic notation](http://en.wikipedia.org/wiki/File_system_permissions#Symbolic_notation), e.g. `'rw-rw-r--'`.

`list() -> List<String>`
: Returns the first-level elements (files and directories) of a directory as a list of strings.

`listFiles() -> List<Path>`
: Returns the first-level elements (files and directories) of a directory as a list of Paths.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ final class TaskPath implements Path, PathEscapeAware {
FilesEx.or(getFileName(),other)
}

List<Path> listFiles(Closure<Boolean> filter = null) {
FilesEx.listFiles(target, filter)
}

String getPermissions() {
FilesEx.getPermissions(target)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ class TaskPathTest extends Specification {

cleanup:
folder.deleteDir()

}

def 'should validate equals method' () {
Expand All @@ -111,10 +110,8 @@ class TaskPathTest extends Specification {
new TaskPath(p1, 'foo.txt').equals(t2)

!t1.equals(t3)

}


def 'should validate operator equality' () {
given:
def p1 = Paths.get('/foo/bar/baz.txt')
Expand All @@ -138,7 +135,6 @@ class TaskPathTest extends Specification {

expect:
new TaskPath(Paths.get('/foo')).size() == 0

}

@Ignore
Expand All @@ -159,10 +155,8 @@ class TaskPathTest extends Specification {

cleanup:
folder.deleteDir()

}


def 'should serialised task path' () {

given:
Expand All @@ -174,7 +168,22 @@ class TaskPathTest extends Specification {
copy.equals(p)
}

}
def 'should support directory listing' () {

given:
def folder = Files.createTempDirectory('test')
folder.resolve('hello.txt').text = 'Hello world'

when:
def path = new TaskPath(folder, 'test')
def result = path.listFiles()

then:
result.size() == 1
result[0].name == 'hello.txt'

cleanup:
folder.deleteDir()
}

}
17 changes: 8 additions & 9 deletions modules/nf-commons/src/main/nextflow/extension/FilesEx.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,8 @@ class FilesEx {
* @param self The folder to list
* @return A list of strings or {@code null} if the path is not a folder
*/
static String[] list(Path self) {
listFiles(self).collect { getName(it) } as String[]
static List<String> list(Path self) {
return listFiles(self).collect { getName(it) }
}

/**
Expand All @@ -636,12 +636,13 @@ class FilesEx {
* @param self The folder to list
* @return A list of {@code Path} or {@code null} if the path is not a folder
*/
static Path[] listFiles(Path self, @ClosureParams(value = FromString.class, options = ["java.nio.file.Path", "java.nio.file.Path,java.nio.file.attribute.BasicFileAttributes"]) Closure<Boolean> filter=null) {
static List<Path> listFiles(Path self, @ClosureParams(value = FromString.class, options = ["java.nio.file.Path", "java.nio.file.Path,java.nio.file.attribute.BasicFileAttributes"]) Closure<Boolean> filter=null) {

if( !self.isDirectory() )
return null

def result = []
final result = []

Files.walkFileTree(self, new SimpleFileVisitor<Path>() {

FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
Expand All @@ -651,19 +652,17 @@ class FilesEx {
}

FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
if( self == dir )
if( self == dir ) {
FileVisitResult.CONTINUE

}
else {
result.add(dir)
FileVisitResult.SKIP_SUBTREE
}
}

} )

return result as Path[]

return result
}

@CompileStatic
Expand Down
Loading