Simplest way to clobber/replace one populated directory with another?
Michael F. Stemper
michael.stemper at gmail.com
Wed May 16 17:09:13 EDT 2018
On 2018-05-15 11:37, Travis Griggs wrote:
> I have a directory structure that might look something like:
>
> Data
> Current
> A
> B
> C
> Previous
> A
> X
>
> In as simple/quick a step as possible, I want to rename Current as Previous including the contents and wiping out the original such that it is now:
>
> Data
> Previous
> A
> B
> C
Is this what you need?
username at hostname$ ll */*
-rw-rw-r-- 1 username username 7 May 16 15:54 Current/1
-rw-rw-r-- 1 username username 7 May 16 15:54 Current/2
-rw-rw-r-- 1 username username 11 May 16 15:54 Current/3
-rw-rw-r-- 1 username username 18 May 16 15:55 Previous/1
-rw-rw-r-- 1 username username 18 May 16 15:55 Previous/2
-rw-rw-r-- 1 username username 14 May 16 15:55 Previous/3
username at hostname$ python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import shutil, os
>>> shutil.rmtree("Previous")
>>> os.rename("Current","Previous")
>>>
username at hostname$ ll */*
-rw-rw-r-- 1 username username 7 May 16 15:54 Previous/1
-rw-rw-r-- 1 username username 7 May 16 15:54 Previous/2
-rw-rw-r-- 1 username username 11 May 16 15:54 Previous/3
username at hostname$
> (I am running on Linux)
If you can do this from a bash script rather than a python program, you
could just do:
#!/bin/bash
rm -r Previous
mv Previous Current
--
Michael F. Stemper
This email is to be read by its intended recipient only. Any other party
reading is required by the EULA to send me $500.00.
More information about the Python-list
mailing list