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@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@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@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@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.
--
https://mail.python.org/mailman/listinfo/python-list