Re: [shoes] Best way to handle getting full path in shoes
- From:
- Wayne Brissette
- Date:
- 2011-10-24 @ 19:19
Let's try this again, making sure plain text is selected. Sorry folks!
I suspect it's just me being the idiot, and trying to think this script
out the way I would have done it in AppleScript, but If I did something
like this in AppleScript:
set SourceFolder to choose folder
tell application "Finder"
set FileNames to name of every file of SourceFolder
end tell
What I guess I'm trying to figure out is how to get shoes to do this same
behavior. That is all me to pick a directory, so that later I can go
through that directory and parse various files. Looking at Eric's example,
he provided the path, but what I'm missing I think is how to get that path
from shoes pick a directory dialog.
> huckle:code eric$ irb
> rbx-head :001 > f = "file.txt"
> => "file.txt"
> rbx-head :002 > File.expand_path f
> => "/Users/eric/code/file.txt"
> rbx-head :003 > File.expand_path f, "/Volumes/some/other/volume"
> => "/Volumes/some/other/volume/file.txt"
> rbx-head :004 >
Also, did the Mac OS X 10.7 version of Shoes ever get released?
Wayne
Re: [shoes] Best way to handle getting full path in shoes
- From:
- Cecil Coupe
- Date:
- 2011-10-25 @ 07:51
Wayne,
Try this little Shoes/Ruby snippet that pops up a dialog box for the
folder name and displays the file names and folder names within.
Shoes.app do
dirString = ask_open_folder
title dirString+":\n"
fileNames = []
Dir.foreach(dirString) do |nm|
fileNames << nm
end
fileNames.each do |foo|
para dirString+"/"+foo+"\n"
end
end
For an Applescripter there are many rubyism's in that snippet that may
confuse you as when mixed into Shoes. In Ruby, there are many ways to
get a file list and I know my example is not the best way, but it does
put up a dialog for a folder, it runs through folder contents and
creates an array of the filenames inside (beware -- sub-folders are
filenames too) and it prints out the full path to the file (or
subdirectory). Dot (.) and Dot-dot (..) are file names and directories.
--Cecil
On Mon, 2011-10-24 at 14:19 -0500, Wayne Brissette wrote:
> Let's try this again, making sure plain text is selected. Sorry folks!
>
> I suspect it's just me being the idiot, and trying to think this script
out the way I would have done it in AppleScript, but If I did something
like this in AppleScript:
>
> set SourceFolder to choose folder
> tell application "Finder"
> set FileNames to name of every file of SourceFolder
> end tell
>
> What I guess I'm trying to figure out is how to get shoes to do this
same behavior. That is all me to pick a directory, so that later I can go
through that directory and parse various files. Looking at Eric's example,
he provided the path, but what I'm missing I think is how to get that path
from shoes pick a directory dialog.
>
>
> > huckle:code eric$ irb
> > rbx-head :001 > f = "file.txt"
> > => "file.txt"
> > rbx-head :002 > File.expand_path f
> > => "/Users/eric/code/file.txt"
> > rbx-head :003 > File.expand_path f, "/Volumes/some/other/volume"
> > => "/Volumes/some/other/volume/file.txt"
> > rbx-head :004 >
>
>
> Also, did the Mac OS X 10.7 version of Shoes ever get released?
>
> Wayne
Re: [shoes] Best way to handle getting full path in shoes
- From:
- Wayne Brissette
- Date:
- 2011-10-25 @ 09:29
Thanks Cecil. This does do what I was wanting to do.
Wayne
Re: [shoes] Best way to handle getting full path in shoes
- From:
- Wayne Brissette
- Date:
- 2011-10-24 @ 19:14
<head><style>body{font-size:10pt;font-family:arial,sans-serif;background-color:#ffffff;color:black;}p{margin:0px;}</style></head><body><font
color="#000000"><font size="2"><font face="arial,sans-serif">I suspect
it's just me being the idiot, and trying to think this script out the way
I would have done it in AppleScript, but If I did something like this in
AppleScript: </font></font></font><div><font class="Apple-style-span"
size="2"><br></font></div><div><div><font color="#000000"><font
size="2"><font face="arial,sans-serif"><p style="margin: 0.0px 0.0px 0.0px
0.0px; font: 12.0px Verdana; color: #1e00c4"><span style="color:
#000000"><b>set</b> </span><span style="color:
#2b9700">SourceFolder</span><span style="color: #000000"> <b>to</b>
</span><b>choose folder</b></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px
Verdana"><b>tell</b> <span style="color:
#3200ff"><i>application</i></span> "Finder"</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Verdana"><span
class="Apple-tab-span" style="white-space:pre"> </span><b>set</b> <span
style="color: #2b9700">FileNames</span> <b>to</b> <span style="color:
#9200e2">name</span> <b>of</b> <b>every</b> <span style="color:
#3200ff"><i>file</i></span> <b>of</b> <span style="color:
#2b9700">SourceFolder</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px
Verdana"><b>end</b> <b>tell</b></p><div><b><br></b></div><div><b><span
class="Apple-style-span" style="font-weight: normal; ">What I guess I'm
trying to figure out is how to get shoes to do this same behavior. That is
all me to pick a directory, so that later I can go through that directory
and parse various files. Looking at Eric's example, he provided the path,
but what I'm missing I think is how to get that path from shoes pick a
directory dialog. </span></b></div><div><b><span
class="Apple-style-span" style="font-weight: normal;
"><br></span></b></div><div><b><span class="Apple-style-span"
style="font-weight: normal; ">Also, did the Mac OS X 10.7 version of Shoes
ever get
released? </span></b></div><div><br></div></font></font></font><blockquote
style="PADDING-LEFT: 5px; MARGIN-LEFT: 0px; BORDER-LEFT: #0000ff 2px
solid"><wasnotrice@gmail.com><zzzhtml><zzzbody style="word-wrap:
break-word; -webkit-nbsp-mode: space; -webkit-line-break:
after-white-space; "><div><div><br></div><div><div>huckle:code eric$
irb</div><div>rbx-head :001 > f = "file.txt"</div><div> =>
"file.txt" </div><div>rbx-head :002 > File.expand_path
f</div><div> =>
"/Users/eric/code/file.txt" </div><div>rbx-head :003 >
File.expand_path f, "/Volumes/some/other/volume"</div><div> =>
"/Volumes/some/other/volume/file.txt" </div><div>rbx-head :004
> </div></div><div><br></div></div></zzzbody></zzzhtml></wasnotrice@gmail.com></blockquote></div></div></body>
Re: [shoes] Best way to handle getting full path in shoes
- From:
- Wayne Brissette
- Date:
- 2011-10-24 @ 09:27
On Oct 22, 2011, at 6:16 AM, J. Kaiden wrote:
> hi Wayne,
>
> welcome to Shoes!
>
> try this:
>
> Dir.entries(folder).each {|indfile| para "files are: " +
File.expand_path(indfile) + "\n"}
Hi all, it's me again. ;)
I'm wondering if this is a Shoes thing, or a Ruby thing, but
File.expand_path isn't returning the right path. Initially I didn't notice
this since I tested this on a directory that was on the same volume as the
test Shoes script. However, when I tried this on a directory that resided
on another volume, my path stayed the same as the previous one. In all
cases it looks like it's using the path to where the script resides, not
where the files are located.
What am I missing? shouldn't the File methods point to the files and not
where the Shoes script resides?
Thanks,
Wayne
Re: [shoes] Best way to handle getting full path in shoes
- From:
- Eric Watson
- Date:
- 2011-10-24 @ 11:22
On Oct 24, 2011, at 4:27 AM, Wayne Brissette wrote:
> Hi all, it's me again. ;)
>
> I'm wondering if this is a Shoes thing, or a Ruby thing, but
File.expand_path isn't returning the right path. Initially I didn't notice
this since I tested this on a directory that was on the same volume as the
test Shoes script. However, when I tried this on a directory that resided
on another volume, my path stayed the same as the previous one. In all
cases it looks like it's using the path to where the script resides, not
where the files are located.
>
> What am I missing? shouldn't the File methods point to the files and not
where the Shoes script resides?
Wayne,
It's a ruby thing ;)
File.expand_path is kind of dumb. It doesn't look for a real path, it just
tells you what the full path to the filename you specify *would be*. With
one argument, it give the full path assuming the file is in the current
directory. If you want the full path to a different directory, just pass
that directory as the second argument. Like this:
huckle:code eric$ irb
rbx-head :001 > f = "file.txt"
=> "file.txt"
rbx-head :002 > File.expand_path f
=> "/Users/eric/code/file.txt"
rbx-head :003 > File.expand_path f, "/Volumes/some/other/volume"
=> "/Volumes/some/other/volume/file.txt"
rbx-head :004 >
Hope that helps!
Eric
Re: [shoes] Best way to handle getting full path in shoes
- From:
- J. Kaiden
- Date:
- 2011-10-24 @ 10:33
hi Wayne,
as far as i understand it, File.expand_path always returns the path that
the script is located in - it can be used for locating other files or
directories relative to where the script is.
if you want to recursively search another directory and extract the paths
of all the files and directories in it, check out the Find module...
http://www.ruby-doc.org/stdlib-1.9.2/libdoc/find/rdoc/Find.html
<http://www.ruby-doc.org/stdlib-1.9.2/libdoc/find/rdoc/Find.html> hth,
- j
Re: [shoes] Best way to handle getting full path in shoes
- From:
- Wayne Brissette
- Date:
- 2011-10-22 @ 13:48
On Oct 22, 2011, at 6:16 AM, J. Kaiden wrote:
> hi Wayne,
>
> welcome to Shoes!
>
> try this:
>
> Dir.entries(folder).each {|indfile| para "files are: " +
File.expand_path(indfile) + "\n"}
>
> hth,
>
> - j
>
Thanks! That worked perfectly. : )
Wayne