directory-traversal 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/directory-traversal.rb +38 -0
- metadata +46 -0
@@ -0,0 +1,38 @@
|
|
1
|
+
module DirTrav
|
2
|
+
#creates a hash representing the directories and files of the directory at path.
|
3
|
+
def dirToHash path
|
4
|
+
hash = Hash[]
|
5
|
+
hash[:name] = path
|
6
|
+
hash[:children] = children = []
|
7
|
+
Dir.foreach(path) do |entry|
|
8
|
+
next if entry == "." or entry == ".."
|
9
|
+
entryPath = File.join(path, entry)
|
10
|
+
if File.directory?(entryPath)
|
11
|
+
children.push dirToHash(entryPath)
|
12
|
+
else
|
13
|
+
children.push entryPath
|
14
|
+
end
|
15
|
+
end
|
16
|
+
return hash
|
17
|
+
end
|
18
|
+
def iterateFiles hash
|
19
|
+
children = hash[:children]
|
20
|
+
for i in children
|
21
|
+
if i.class == Hash
|
22
|
+
iterateFiles(i) {|a| yield a}
|
23
|
+
else
|
24
|
+
yield i
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
def iterateDirs hash
|
29
|
+
children = hash[:children]
|
30
|
+
name = hash[:name]
|
31
|
+
yield name
|
32
|
+
for i in children
|
33
|
+
if i.class == Hash
|
34
|
+
iterateDirs(i) {|a| yield a}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: directory-traversal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Eigil Rischel
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-30 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Provides a few simple methods to make traversing directories a bit easier
|
15
|
+
and more powerful
|
16
|
+
email: ayegill@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/directory-traversal.rb
|
22
|
+
homepage: http://rubygems.org/gems/directory-traversal
|
23
|
+
licenses: []
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 1.8.24
|
43
|
+
signing_key:
|
44
|
+
specification_version: 3
|
45
|
+
summary: Provides simple functionality for traversing directories
|
46
|
+
test_files: []
|