Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3969576
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:58:48+00:00 2026-05-20T03:58:48+00:00

I’m writing a backup script, which uses hard links to not consume space for

  • 0

I’m writing a backup script, which uses hard links to not consume space for unmodified files.

I’d like to check if a given file system (as determined from a specific directory) supports hard links at the start of the script – otherwise, it could get half-way through (copying multiple files) before the first hard link needs creating, causing the script drops out with an exception (which I could recover by reverting changes or silently changing hard links to full copies, but I don’t really want either – I’d just rather not start if it’s going to hit this issue).

So, how do I check if the file system supports hard links if the only available input is a string containing a directory location (eg "F:\\Backups" or similar)?

Failing that, is there a nice way to check the type of file system that a particular directory is on?
I suppose could just pull that and then work out if it’s supported or not from there?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T03:58:49+00:00Added an answer on May 20, 2026 at 3:58 am

    I’d tackle this problem this way: There are 3 alternatives for copying a file:

    1. On Unix, you can use os.link.
    2. On Windows, you can use a function like this:

      def CreateHardLink(src, dst):
          import ctypes 
          if not ctypes.windll.kernel32.CreateHardLinkA(dst, src, 0):
              raise OSError
      

      (Disclaimer: I haven’t tested it. The idea is to use the kernel32 API.)

    3. If all this fails, you can still make a regular file copy (for example, with shutil.copy2).

    Then, you can test these 3 functions at the beginning of the script with a temporary file (to be deleted afterwards). The first of these 3 functions that succeeds (that is, the first one that raises no Exception) is a good candidate for making the actual backup copies.

    This idea follows a strategy pattern, where you have to select a function that takes the source and destination filenames and makes the best effort to make the copy the way you want it.

    Let me add one more thing: Detecting the filesystem in order to choose a copying strategy is not a very good practice in the same way that detecting browsers is not a good practice to do different things in Javascript. It’s always best to try to use a feature and be prepared to catch exceptions or handle errors in order to produce an alternative result.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have some data like this: 1 2 3 4 5 9 2 6
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.