Comments (7)
@watzon Thanks! After some more investigation I think you are right. I made a mistake.
This Dir["**/*"].each
is a little magical. 😅
I am closing this issue now.
And I will try to add the implementation in Crystal for the walkdir_test project soon.
from crystal-libraries-needed.
What's wrong with Dir
? What are you wanting the shard to be able to do?
Currently with Dir
you can do:
Dir["**/*"].each do |f|
puts f
end
from crystal-libraries-needed.
Hi @watzon ! Please read at least one of the implementations e.g. Python I referred, and find if it is already implemented in Crystal. Please update me if I missed something. Thank you!
from crystal-libraries-needed.
@zhangkaizhao I have looked through all of the implementations and I haven't seen much of anything that can't be done with plain Crystal. That's why I want to know what your use-case is. What are you wanting to do that you can do in one of those libs, but not with Dir
?
from crystal-libraries-needed.
This is my pull request lilydjwg/walkdir-test#1 .
The class method Dir.[](*patterns) : Array(String)
returns an Array. This might be an issue when there are too many files in the directory.
You can improve it if you have a better idea.
Without this method, I have to open sub directories recursively:
def count(dir)
count = 0
dir.each_child do |filename|
subpath = File.join dir.path, filename
filetype = File.info(subpath, follow_symlinks: false).type
if filetype.directory?
count += count(Dir.new(subpath))
elsif filetype.file? && filename.downcase.ends_with?(".jpg")
count += 1
end
end
dir.close
count
end
puts count(Dir.new(ARGV[0]))
and this maybe hits the recursion limit for too deep sub directories.
And another problem is when I run without the line dir.close
from the above source code I get an issue which complains of "Too many open files" if the number of files is a little bigger:
$ ./walk ~/repos/github.com/
Unhandled exception: Error opening directory '/home/kaizhao/repos/github.com/ziglang/zig.wiki/.git/logs/refs': Too many open files (Errno)
Failed to raise an exception: END_OF_STACK
[0x563f100af6b6] ???
[0x563f10096edb] __crystal_raise +43
[0x563f10097e6c] ???
[0x563f1009f380] ???
[0x563f1009a94c] ???
[0x563f10099a3d] ???
[0x563f100a2787] ???
[0x563f100aaf4c] ???
[0x563f10098e97] main +55
[0x7f7f5edf9ee3] __libc_start_main +243
[0x563f100954fe] _start +46
[0x0] ???
I don't know if this is an issue.
from crystal-libraries-needed.
The class method Dir. : Array(String) returns an Array. This might be an issue when there are too many files in the directory.
You can use Dir.glob
with a block if you want to avoid creating an array
from crystal-libraries-needed.
@brew Thank you! I have updated the pull request with Dir.glob
.
from crystal-libraries-needed.
Related Issues (20)
- Web scraper HOT 3
- Suggestion: port gem mimemagic from Ruby for significant (and fully platform agnostic) MIME type coverage
- Push notification service
- Port of impersonator gem
- fastimage shard HOT 3
- XMPP / Jabber client shard HOT 2
- Font renderer HOT 7
- Relational Algebra
- Math parser / evaluator HOT 6
- Flashtext port
- Tokyo Tyrant (Tokyo Cabinet server) HOT 4
- Python to Crystal converter HOT 3
- Data-parallelism library
- Algorithmic Trading Library
- integration with a browser recording library: playwright library / puppeteer library / something similar HOT 5
- A rewrite of Centrifuge use crystal
- Kubernetes API HOT 2
- RDF library
- HAML templating Shard HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crystal-libraries-needed.