Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug for filep and dirp function #6

Closed
russellfei opened this issue Jul 31, 2014 · 6 comments
Closed

Bug for filep and dirp function #6

russellfei opened this issue Jul 31, 2014 · 6 comments

Comments

@russellfei
Copy link

My proposed to check image files exist in specific directory and probably in sub directory of the input directory.

However, both filep and dirp return falsewhen my code called them.
The only way for return true is that I change directory to destination directory and use th to call trepl and call filep and dirp.

I've checked the document in repo and it doesn't give me enough information to figure out this.

Anyone has any ideas or hints?

Thanks~

@soumith
Copy link
Member

soumith commented Jul 31, 2014

if you give a sample snippet of code (10 lines or less), i'll correct it.

@russellfei
Copy link
Author

Thankfully, the major part of this problem can be represented in about 10 lines

-- image folder string acquired through op
-- not counted for total 10 line requirements ;-)
op = xlua.OptionParser('load-images.lua [options]')
op:option{'-d', '--dir', action='store', dest='dir', help='directory to load', req=true}

-- main function
local current_dir = opt.dir
checkFile = function( current_dir )
    local list = paths.dir( current_dir )
    table.sort(list, function (a,b) return a<b end)
    for i = 3, #list do
        -- there's a problem about the list[i]
        -- what kind of input format (string? but I come across error several times) 
        -- will generate the  desired output?
        if paths.filep( list[i] ) and checkExtensionName( list[i], opt.ext ) then
            print( ' ==> found file '.. list[i] )
        else
            print( '==> check sub directory ' .. list[i])
            --> go to check sub dir function
       end
    end
end

Thx~

@soumith
Copy link
Member

soumith commented Aug 1, 2014

well, you have to do: paths.filep( paths.concat(current_dir, list[i]))

@russellfei
Copy link
Author

Really surprised and appreciated for your answer in maybe midnight.
Well, this is the following test I tried, but cmd window just show false.
As a result, I'm REALLY confused.. 0.0
my second trial code:

 print( 'concat path:' .. tostring( paths.concat( current_dir, list[1] ) ))

I guess paths.filep is related on the cwd and there's something intractable
in passing string parameters. @_@

@soumith
Copy link
Member

soumith commented Aug 1, 2014

Here's a corrected gist.
https://gist.github.com/f4dd3ee76c8251f6e91a

It works for me. Here's the output given torch7 as the dir:

==> check sub directory /home/fatbox/code/torch7/.git
 ==> found file /home/fatbox/code/torch7/.travis.yml
 ==> found file /home/fatbox/code/torch7/CMakeLists.txt
 ==> found file /home/fatbox/code/torch7/COPYRIGHT.txt
 ==> found file /home/fatbox/code/torch7/CmdLine.lua
 ==> found file /home/fatbox/code/torch7/DiskFile.c
 ==> found file /home/fatbox/code/torch7/FFI.lua
 ==> found file /home/fatbox/code/torch7/File.c
 ==> found file /home/fatbox/code/torch7/File.lua
 ==> found file /home/fatbox/code/torch7/Generator.c
 ==> found file /home/fatbox/code/torch7/MemoryFile.c
 ==> found file /home/fatbox/code/torch7/PipeFile.c
 ==> found file /home/fatbox/code/torch7/README.md
 ==> found file /home/fatbox/code/torch7/Storage.c
 ==> found file /home/fatbox/code/torch7/Tensor.c
 ==> found file /home/fatbox/code/torch7/Tensor.lua
 ==> found file /home/fatbox/code/torch7/TensorMath.lua
 ==> found file /home/fatbox/code/torch7/TensorOperator.c
 ==> found file /home/fatbox/code/torch7/Tester.lua
 ==> found file /home/fatbox/code/torch7/Timer.c
==> check sub directory /home/fatbox/code/torch7/build
==> check sub directory /home/fatbox/code/torch7/cmake
==> check sub directory /home/fatbox/code/torch7/doc
 ==> found file /home/fatbox/code/torch7/general.h
==> check sub directory /home/fatbox/code/torch7/generic
 ==> found file /home/fatbox/code/torch7/hist.lua
 ==> found file /home/fatbox/code/torch7/init.c
 ==> found file /home/fatbox/code/torch7/init.lua
==> check sub directory /home/fatbox/code/torch7/lib
 ==> found file /home/fatbox/code/torch7/random.lua
==> check sub directory /home/fatbox/code/torch7/rocks
==> check sub directory /home/fatbox/code/torch7/test
 ==> found file /home/fatbox/code/torch7/torchcwrap.lua
 ==> found file /home/fatbox/code/torch7/utils.c
 ==> found file /home/fatbox/code/torch7/utils.h

@russellfei
Copy link
Author

Thanks, soumith.
I'll try it later and update my result here. :-)

The usage of absolute path and relative path is the cause for this problem.

More specifically, several details should be written here for others:

  • the current_dir and directory string given to -d should be set correspondingly
  • if relative path (just like this gist does) is used, the pwd or cwd you type th matters, i.e., mismatch results in such errors like this
  • Is there any fail-safe setting? Yes! Use absolute path or relative path begin with ~ ;-)

@soumith soumith closed this as completed Oct 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants