# At the first example you should pass a block to the iterator
Pathname(Dir.home).each_entry {|entry| p entry.realpath }

# The second, it's probably what it's telling you. The (actual) file
doesn't exist.
Only the symlink.

# I did
ln -s non-existing-dir/ my-symlink

# And now I have a symlink called "my-symlink" pointing to a "non-existing-dir".

# Now if I try:
Dir.foreach("/#{Dir.home}/") { |entry| p Pathname(entry).realpath }

# It gives me
Errno::ENOENT: No such file or directory - /Users/abinoam/non-existing-dir
from (irb):35:in `realpath'
from (irb):35:in `realpath'
from (irb):35:in `block in irb_binding'
from (irb):35:in `foreach'
from (irb):35
from /Users/abinoam/.rvm/rubies/ruby-1.9.3-p429/bin/irb:16:in `<main>'

# If I just create the non-existing-dir

mkdir non-existing-dir

# It just pass ok.

You're going well!

Keep going,
Abinoam Jr.

On Sat, Jan 11, 2014 at 5:02 PM, Matthew Stevenson <lists / ruby-forum.com> wrote:
> tldr: Having trouble getting the target of symlinks within a specified
> directory.
>
> My apologies for a very newbish question here.
> Background: As a learning exercise I want to write a program that will
> sync folders between my desktop and my Android phone using `adb push`.
> I know there are already apps that do this, but it seems a nice starter
> project to learn something from.
>
> I have a script that will create a hidden desktop directory for each
> type of file to be synced (music, pictures, movies, etc).  I have a
> script that will provide an entry on right click menus for "sync to
> android" with sub-entries for each category.  This creates a symlink to
> the selected file or directory in the "sync" directory.
>
> Problem: adb push does not work with symlinks.  I need my "sync" script
> to read over the symlinks in the sync directories and return the target
> paths to `adb push`.  I have tried any number of ways to make this
> happen and come up short.  Any assistance is needed.  Examples of things
> that do not work below:
>
> Pathname("/#{Dir.home}/.ANDROIDMUSIC").each_entry.realpath => 'foreach':
> no block given (LocalJumpError)
>
> Dir.foreach("/#{Dir.home}/.ANDROIDMUSIC") { |entry|
> Pathname(entry).realpath } => in 'realpath': No such file or directory -
> /current/directory/with_file_from_specified_directory_appended.mp3
>
> --
> Posted via http://www.ruby-forum.com/.