# FileUtils.ln cross platform?

**URL:** <https://www.ruby-forum.com/t/fileutils-ln-cross-platform/106650>\
**Category:** Ruby\
**Created:** [June 12, 2007, 8:52pm UTC](https://www.ruby-forum.com/t/fileutils-ln-cross-platform/106650 "2007-06-12T20:52:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [June 12, 2007, 8:52pm UTC](https://www.ruby-forum.com/t/fileutils-ln-cross-platform/106650/1 "2007-06-12T20:52:08Z")

</div>

What happens when you use FileUtils.ln on a Windows system. Does it  
fail? Is that why Jim W. uses #safe\_ln, eg.

LINKING\_SUPPORTED = [true]

# Attempt to do a normal file link, but fall back

# to a copy if the link fails.

def safe\_ln(\*args)  
unless LINKING\_SUPPORTED[0]  
cp(\*args)  
else  
begin  
ln(\*args)  
rescue Errno::EOPNOTSUPP  
LINKING\_SUPPORTED[0] = false  
cp(\*args)  
end  
end  
end

If so, is there a better way? Or why wouldn’t this be built into Ruby.

Thanks,  
T.

---

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [June 12, 2007, 10:43pm UTC](https://www.ruby-forum.com/t/fileutils-ln-cross-platform/106650/2 "2007-06-12T22:43:29Z")

</div>

On Jun 12, 12:51 pm, Trans [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> else
> 
> ```
> 
> Thanks,  
> T.

With 1.8.5 FileUtils.ln simply copied the file. Without digging into  
changelogs, I can only speculate that it may have been an unsupported  
op in earlier versions of Ruby, and that’s why Jim added extra code.

Note that with the advent of Vista the issue of symlinks on Windows  
will need to be revisited.

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [June 13, 2007, 12:41am UTC](https://www.ruby-forum.com/t/fileutils-ln-cross-platform/106650/3 "2007-06-13T00:41:48Z")

</div>

On Jun 12, 4:41 pm, Daniel B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > # to a copy if the link fails.
> > 
> > ```
> > end
> > 
> > ```
> > 
> > end
> 
> > If so, is there a better way? Or why wouldn’t this be built into Ruby.
> 
> > Thanks,  
> > T.
> 
> With 1.8.5 FileUtils.ln simply copied the file. Without digging into  
> changelogs, I can only speculate that it may have been an unsupported  
> op in earlier versions of Ruby, and that’s why Jim added extra code.

Excellent. Glad I don;t have to mess with it. Thanks Dan!

> Note that with the advent of Vista the issue of symlinks on Windows  
> will need to be revisited.

Indeed. I heard it supports them, but later heard that they aren’t  
really the same thing. Are you using Vista yet. Do you know?

T.

---

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [June 13, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/fileutils-ln-cross-platform/106650/4 "2007-06-13T16:31:21Z")

</div>

On Jun 12, 4:41 pm, Trans [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Jun 12, 4:41 pm, Daniel B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Note that with the advent of Vista the issue of symlinks on Windows  
> > will need to be revisited.
> 
> Indeed. I heard it supports them, but later heard that they aren’t  
> really the same thing. Are you using Vista yet. Do you know?
> 
> T.- Hide quoted text -

I don’t have Vista yet. I’m waiting until Leopard is released, at  
which point I’ll setup a dual boot config on my Mac tower. Hopefully,  
SP 1 will be out by then.

As for whether or not they’re the same thing, the docs for  
CreateSymbolicLink() sure seem to indicate they are:

> **[CreateSymbolicLinkA function (winbase.h) - Win32 apps](https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createsymboliclinka?redirectedfrom=MSDN)**
>
> Creates a symbolic link. (ANSI)

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [June 14, 2007, 12:33am UTC](https://www.ruby-forum.com/t/fileutils-ln-cross-platform/106650/5 "2007-06-14T00:33:51Z")

</div>

On Jun 13, 10:30 am, Daniel B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > really the same thing. Are you using Vista yet. Do you know?  
> > [CreateSymbolicLinkA function (winbase.h) - Win32 apps | Microsoft Learn](http://msdn2.microsoft.com/en-us/library/aa363866.aspx)  
> > Yup. You are right.

“Microsoft has implemented its symbolic links to function just like  
UNIX links.”

– [Symbolic Links - Win32 apps | Microsoft Learn](http://msdn2.microsoft.com/en-us/library/aa365680.aspx)

Somewhere I picked up some bad info. Thanks for setting me straight.

T.
