Move subfolders with python

1

Good morning, at some point I've been trying to create a python script to search sub directories from one folder to another for example:

root
-pasta1
--pastaa
--pastab
-pasta2
-pasta3
--pastac
--pastad

I've been unsuccessfully trying to get my python script to search the subdirectories of my root folder, and the folders "foldera, folderb, folderc, and pastad" are moved to a directory above the root directory. Any ideas?

    
asked by anonymous 18.05.2016 / 16:45

1 answer

0

Given that your python script is root in an example to change the contents of folders 1 and 3 up, a level would be:

from subprocess import Popen
Popen('mv ./pasta1/* .', shell=True)
Popen('mv ./pasta3/* .', shell=True)

For this purpose you have to call up the "Popen" function of the subprocess package, since the call function does not interpret the "*" character as "any value".

    
26.05.2016 / 10:58