moving multiple directories

D

DataSmash

Hi,
I need to organize thousands of directories full of files.
I want to move these directories into other subdirectories.
For example, all the directories that start with 01, move to
a directory named "one", all directories that start with 02, move
to a directory name "two", and so on....

I can't seem to find any easy way to do this.
Looks like shutil.move only lets you move if the subdirectory DOES
NOT exist, so after the first directory moves, the script blows up on
the second move.
I guess you could use shutil.copy or shutil.copytree but then you have
to
delete as well. Much longer process when you have hundreds of
gigabytes of data.

Thanks for your help!
R.D.
 
L

Larry Bates

DataSmash said:
Hi,
I need to organize thousands of directories full of files.
I want to move these directories into other subdirectories.
For example, all the directories that start with 01, move to
a directory named "one", all directories that start with 02, move
to a directory name "two", and so on....

I can't seem to find any easy way to do this.
Looks like shutil.move only lets you move if the subdirectory DOES
NOT exist, so after the first directory moves, the script blows up on
the second move.
I guess you could use shutil.copy or shutil.copytree but then you have
to
delete as well. Much longer process when you have hundreds of
gigabytes of data.

Thanks for your help!
R.D.
Use win32.moveFile method instead. This links directly to the Windows
MoveFile method that just moves the directory entries around.

From Win32 Documentation:

win32api.MoveFile
MoveFile(srcName, destName)

Renames a file, or a directory (including its children).

Parameters

srcName : string

The name of the source file.

destName : string

The name of the destination file.

Comments
This method can not move files across volumes.

-Larry
 
I

ici

Use win32.moveFile method instead. This links directly to the Windows
MoveFile method that just moves the directory entries around.

From Win32 Documentation:

win32api.MoveFile
MoveFile(srcName, destName)

Renames a file, or a directory (including its children).

Parameters

srcName : string

The name of the source file.

destName : string

The name of the destination file.

Comments
This method can not move files across volumes.

-Larry

Instead win32api, use "native" shutil module

import shutil
shutil.move(src,dest)

Recursively move a file or directory to another location.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top