Project

General

Profile

Actions

Feature #3356

closed

Add GetShortPathName to ruby

Added by docwhat (Christian Höltje) almost 14 years ago. Updated about 8 years ago.

Status:
Feedback
Target version:
-
[ruby-core:30470]

Description

=begin
Hi!

I use Ruby on windows and it would be really useful to have access to GetShortPathName in ruby.

I have a monkey-patch to add Pathname.shortpath (attached) to demonstrate it. Probably realpath, etc. should take this in to account as well, since in windows, only the shortpath is canonical.

In addition, the shortpath doesn't need to be escaped, so you can use it with backticks (`), etc.

Ciao!
=end


Files

pathname-shortpath.rb (640 Bytes) pathname-shortpath.rb Monkey patch to pathname docwhat (Christian Höltje), 05/28/2010 01:42 AM
Actions #1

Updated by akr (Akira Tanaka) almost 14 years ago

=begin
2010/5/28 Christian Höltje :

Bug #3356: Add GetShortPathName to ruby
http://redmine.ruby-lang.org/issues/show/3356

I use Ruby on windows and it would be really useful to have access to GetShortPathName in ruby.

I think it should be defined as a class method of File at first,
as other many methods in Pathname.

Tanaka Akira

=end

Updated by rogerdpack (Roger Pack) over 12 years ago

I could use this as well (because some File-like classes return an 8.3 filename, some the full filename, so not always is the 8.3 name available), though ffi is or winapi is a good work-around for the present.

Updated by mame (Yusuke Endoh) almost 12 years ago

  • Description updated (diff)
  • Status changed from Open to Assigned
  • Assignee set to nobu (Nobuyoshi Nakada)

Updated by nobu (Nobuyoshi Nakada) almost 12 years ago

  • Status changed from Assigned to Feedback
  • Assignee deleted (nobu (Nobuyoshi Nakada))
  • Priority changed from Normal to 3

What do you mean by "canonical"?
It doesn't feel like "canonical" at all.

Updated by mame (Yusuke Endoh) over 11 years ago

  • Target version set to 2.6

Updated by luislavena (Luis Lavena) over 11 years ago

  • Assignee set to usa (Usaku NAKAMURA)

Hello,

AFAIK shortnames might not be available on some NTFS volumes, under some circumstances I found is off for performance.

Shortname version of a filename is not canonical, is just one of many representations of a file in the filesystem.

If the intention is use short_name to be able to shell out, why not improve Windows support on ShellWords so it properly escapes the path instead?

We keep improving Ruby on Windows to properly support long names and path with spaces that adding this seems counter productive from my point of view.

I'm assigning to Nakamura-san for decision.

Thank you.

Updated by usa (Usaku NAKAMURA) over 11 years ago

Hello,

In message "[ruby-core:49766] [ruby-trunk - Feature #3356] Add GetShortPathName to ruby"
on Nov.21,2012 00:17:14, wrote:

Shortname version of a filename is not canonical, is just one of many representations of a file in the filesystem.

agreed.
I've realized that the shortname is a kind of a hardlink.

If the intention is use short_name to be able to shell out, why not improve Windows support on ShellWords so it properly escapes the path instead?

We keep improving Ruby on Windows to properly support long names and path with spaces that adding this seems counter productive from my point of view.

agreed.

However, improving the longname (expecially including spaces) is not
conflict to add a new method to get shortname, I think.
Since I do not have a usecase of the method, I cannot judge whether
the method is necessery or not.
Therefore, users who need the method should show some suitable usecases.
Of course, as menthioned above, to gloss over the problems in ruby itself
with handling longnames.

Regards,

U.Nakamura

Updated by sschuberth (Sebastian Schuberth) about 8 years ago

Usaku NAKAMURA wrote:

Since I do not have a usecase of the method, I cannot judge whether
the method is necessery or not.
Therefore, users who need the method should show some suitable usecases.

I'd also like to see a "shortpath" method implemented, but also the opposite "longpath" (like suggested at [1]).

My use-case is that I need de-duplicate a list of Windows paths, i.e. generate a list of unique paths. The list may contain short paths as well as long paths, so a solution would be to first convert all paths to their long form, and then do case-insensitive string matches. Currently, that does not seem possible in Ruby as there's not way to explicitly get a long path for a short path (also see [2]) or vice versa. If we have a "longpath" (or "shortpath) we should also have a "shortpath" (or "longpath") for symmetry.

[1] http://stackoverflow.com/a/8142448/1127485
[2] http://stackoverflow.com/q/34919422/1127485

Updated by nobu (Nobuyoshi Nakada) about 8 years ago

You can get the stored name by File.realpath, and tell if two files are same by File.identical?.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0