Nodachisoft Nodachi Sword Icon
  
@Amaji✎ Update September-29-2020

Move and copy files to another folder using Python

This program moves files such as "*.png" and "*.gif" in a folder to the other folder.

I'm publishing a "code snippet" tag to show what I've made in batches and small code that I think I can use.

Tested Environment

  • python 2.7.15, 3.8.5

code

 
exmove.py(move-files-to-another-folder)
import os
import shutil
import glob

def exmove( srcdir, destdir, srcfiles ):
	for fpattern in srcfiles:
		globsearch = os.path.join( srcdir, fpattern )
		for fpath in glob.glob(globsearch):
			shutil.move(fpath, destdir)

# RUN
exmove( "./from", "./to", ["*.jpg", "*.gif"] )

In this case, the code will move all files with jpg and gif extensions in the "from" directory under the current directory to the "to" directory under the current directory.

The usage here.

exmove( SOURCE DIR , DEST DIR , Array of FilePatterns )

When you call the exmove function, you can move the file from "./from" directory to "./to" directory.

thas's all

References

Modifications

  • 2020-09-29 First Published
 
 
Message sent

Thank you for your message.

Something error has occured!

Sorry. The Error has occurred.We apologize for the inconvenience.Please try again in a few minutes or contact us via DM below.

Twitter:@NodachiSoft_eng
Name:
 
Replay To:
 
Message:
 
Back
Check the content!

Send the following information to us. If you are happy with your submission, please click "Send". If you want to modify it, please click "Back".

Name:
 
Reply To:
 
Message:
 
Enter a confirmation key to make sure that you are not operating from a Robot.
Confirmation Key is 95
Back
 / 
Go to Confirmation
Entry fields
Go to Confirmation

There are 1 articles that may be relevant!

Generate an Array of Prime numbers in python

#Python#Code snipet#CTF✎ 2020-10-16
Generate an Array of Prime numbers in python
広告領域
追従 広告領域
Table Of Contents
Move and copy files to another folder using Python
Move and copy files to another folder using Python
Tested Environment
Tested Environment
code
code
RUN
RUN
References
References
Modifications
Modifications
Nodachisoft © 2020