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 8274507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:44:59+00:00 2026-06-08T07:44:59+00:00

I’m using Python 2.7.3. I’m working on a Python script to copy parts of

  • 0

I’m using Python 2.7.3. I’m working on a Python script to copy parts of a directory tree from one location to another. Some of the files that need to be copied are symlinks.

How can I use Python to copy symlinks from location to another without following them? (I just want it to blindly copy them just like they are ‘regular’ files)

I found that shutil.copy() for Python 3.3 supports the argument follow_symlinks=False, yet older versions of shutil doesn’t.

EDIT: More details:

The purpose of this script is to take all files from a specified location and split them up into individual archives. I know I could do this by zipping up the entire directory and splitting the archive, but I need to have the capability of extracting each archive individually without rejoining into one large archive. Also, each archive must be less than a specified size.

Basic approach:

  1. Get all absolute paths to all files of source directory
  2. Get all sizes of all files
  3. Sort all files (regardless of location) by size
  4. Copy files from location X to tmp location (until sum of copied files is <= to max archive size)
  5. Create archive of tmp
  6. Clean tmp location
  7. Go back to 4 while there are still files to copy

Any feedback would be appreciated. Thanks.

  • 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-06-08T07:45:00+00:00Added an answer on June 8, 2026 at 7:45 am

    Copying parts of a directory tree, you say? In that case, try shutil.copytree().

    If symlinks is true, symbolic links in the source tree are represented as symbolic links in the new tree, but the metadata of the original links is NOT copied; if false or omitted, the contents and metadata of the linked files are copied to the new tree.

    So as long as you don’t need to keep the metadata the same, this should work just fine (actually, can symlinks on their own even have such metadata, or do they just reference the metadata of the file/object they point to?). Also note that you don’t have to copy the entire tree with copytree(); the ignore argument allows you to provide a callable that will prune down the files and directories to copy.

    One thing to watch out for, though: If you modify the contents list passed in to the ignore callable, that will also affect what is copied (as you can see in the copytree() source code).


    (Copying/paraphrasing from comments)

    As the implementation of shutil.copytree() shows how copytree() handles symbolic links (linkto = os.readlink(srcname); os.symlink(linkto, dstname)), that can be used as a reference for how to “copy” symbolic links even if copytree() itself is not useful.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.