Skip to content

Commit

Permalink
paths.indexdir(...,ignore)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholas-leonard committed Jul 22, 2015
1 parent 3c4969a commit 5e72798
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ torch.md5.sumhexa('helloworld!')
```

<a name="paths.indexdir"/>
### [obj] paths.indexdir(path, ext, use_cache) ###
### [obj] paths.indexdir(path, [ext, use_cache, ignore]) ###
```lua
files = torch.indexdir("/path/to/files/", 'png', true)
images = {}
Expand All @@ -196,4 +196,5 @@ This function can be used to create an object indexing all files having
extensions `ext` (a string or a list thereof) in directory `path` (string or list thereof).
Useful for directories containing many thousands of files. The function
caches the resulting list to disk in `/tmp` such that it can be used
for later calls when `use_cache=true` (default is false).
for later calls when `use_cache=true` (default is false).
Argument `ignore` species a pattern to ignore (e.g. "*frame*" will ignore all files containing `"frame"`).
5 changes: 4 additions & 1 deletion indexdir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- e.g. fileList = torch.indexdir("/path/to/files/", 'png', true)
-- index the directory by creating a chartensor of files paths.
-- returns an object with can be used to efficiently list files in dir
function paths.indexdir(pathList, extensionList, use_cache)
function paths.indexdir(pathList, extensionList, use_cache, ignorePattern)
extensionList = extensionList or {'jpg', 'png','JPG','PNG','JPEG', 'ppm', 'PPM', 'bmp', 'BMP'}
extensionList = (torch.type(extensionList) == 'string') and {extensionList} or extensionList

Expand Down Expand Up @@ -35,6 +35,9 @@ function paths.indexdir(pathList, extensionList, use_cache)
for i=2,#extensionList do
findOptions = findOptions .. ' -o -iname "*.' .. extensionList[i] .. '"'
end
if ignorePattern then
findOptions = '! -iname "'..ignorePattern..'" \\(' .. findOptions .. " \\)"
end

for i, path in ipairs(pathList) do
-- run "find" on each directory, and concatenate all
Expand Down

0 comments on commit 5e72798

Please sign in to comment.