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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:19:08+00:00 2026-05-26T08:19:08+00:00

A script I wrote was meant to move individual day directories from an old

  • 0

A script I wrote was meant to move individual day directories from an old location to a new location with a structure like this:

/old/YYYY/MM/DD
/new/YYYY/MM/DD

and for another task (unrelated to the moving of data) I created a softlink in the new location like this (this was the first mistake I made):

/new/2011/09 -> /old/2011/09

My script essential used this function call:

for d in os.listdir("/old/2011/09"):
    shutil.move(os.path.join("/old/2011/09/", d), os.path.join("/new/2011/09", d))

After running my script 2011/09 was empty in both. I had this occur at work with unarchived data…big problem. My question is why didn’t shutil.move() give me an error that the day directory I was moving already existed? Each day inside 09 should have been the same directory because of the softlink.

/new/2011/09/01 == /old/2011/09/01

Doesn’t the shutil.move call check the src and dst before calling shutil.copy2? From the docs: “The destination directory must not already exist.” or is that only when it uses rename? AND if it makes a difference both old and new locations were glusterfs.

shutil.move Documentation

shutil.copy Documentation

Thanks for any clarity you can provide.

EDIT/UPDATE: I submitted a question to the python-list asking why this behavior existed and asked if it should be changed (list archive). They suggested I file a bug report. While doing the tests to submit the bug I found out that this has been fixed in Python 2.7. You can see the differences in the source in the move function declaration: Python 2.6 and Python 2.7.

This still does the move/rename but won’t magically delete an entire directory.

  • 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-26T08:19:08+00:00Added an answer on May 26, 2026 at 8:19 am

    It comes down to these two lines in shutil.move:

            copytree(src, real_dst, symlinks=True)
            rmtree(src)
    

    where src='old' and real_dst='new/old'. The copytree command copies old to the subdirectory new/old. That goes fine, although it may not be what you intended.

    rmtree removes the old directory. That’s a problem, since new is now a dangling symlink.

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

Sidebar

Related Questions

I wrote this script which counts occurrences of particular pattern in a given file.
I wrote this script to for a contact form on my website, everything works
I wrote this script some months ago, and now rereading it, I'm unable to
Here's the code from sys import argv script,from_file, to_file = argv open(to_file,'w').write(open(from_file).read()) I'm new
Last day I wrote a script so that my J2ee app could do backups.
I wrote a bash script that fetches lyrics from a website. The script is
I wrote this script https://gist.github.com/1313611 to ease my installs for rvm. The whole script
I have a Perl script I wrote for my own personal use that fetches
following is the bash script I wrote for Sqlite. #!/bin/bash sqlite3 file.db CREATE TABLE
I'm having a Firefox-specific issue with a script I wrote to create 3d layouts.

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.