Created
May 18, 2014 18:44
-
-
Save robertsky/37b59726d98b3ec4be2f to your computer and use it in GitHub Desktop.
A quick cobbling of Ruby codes to do a directory listing of hard disk(s).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#name: quick_directory_listing.rb | |
#author: robertsky | |
#url: http://robertsky.com | |
#github: https://github.com/robertsky | |
#gem install sys-filesystem | |
#https://github.com/djberg96/sys-filesystem | |
require 'sys/filesystem' | |
curDir = Dir.pwd | |
$out2 = nil | |
$multipler = 1 | |
def subDirWalk(f) | |
out = $out2 | |
if File.directory?(f) | |
out.puts "\t"*$multipler+"<directory>#{f}" | |
Dir.chdir(f) | |
Dir.glob("*").each do |e| | |
$multipler += 1 | |
subDirWalk(e) | |
end | |
out.puts "\t"*$multipler+"</directory>" | |
Dir.chdir("..") | |
elsif File.file?(f) | |
out.puts "\t"*$multipler+"<file size=\"#{File.size(f)}\">#{f}</file>" | |
end | |
$multipler -=1 | |
#dirty fix to ensure that there will be at least one "\t" spacing. | |
if $multipler < 1 then $multipler = 1 end | |
end | |
#a, b are the volumes path, escaped and unescaped respectively. number is the number of the hard disk I have processed. | |
a = "/Volumes/HDD\ Four" | |
b = "/Volumes/HDD Four" | |
number = 4 | |
open(number.to_s + "_all_files.xml", "w"){ |out| | |
$out2 = out | |
Dir.chdir(a) | |
out.puts "<all_files>" | |
#quick dirty writing of information I want | |
out.puts "\t<details>" | |
out.puts "\t\t<volume>#{b}</volume>" | |
out.puts "\t\t<volume_num>#{number.to_s}</volume_num>" | |
stat = Sys::Filesystem.stat(b) | |
out.puts "\t\t<block_size>#{stat.block_size}</block_size>" | |
out.puts "\t\t<blocks>#{stat.blocks}</blocks>" | |
out.puts "\t\t<blocks_available>#{stat.blocks_available}</blocks_available>" | |
out.puts "\t</details>" | |
Dir.glob("*").each do |f| | |
subDirWalk(f) | |
end | |
out.puts "</all_files>" | |
} | |
Dir.chdir(curDir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment