Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

How to Move and Delete Files in Python

import os

os.rename('./blogs/1.txt', './blogs/Test Directory 1/1.txt')
os.rename('./blogs/2.txt', './blogs/Test Directory 2/1.txt')

# So, in the first rename method, we are taking 1.txt from the blogs directory and moving it to Test Directory 1 which is a subdirectory of blogs.
# In the second scenario, we are taking 2.txt and moving it to the Test Directory 1 directory with the name 1.txt.
# Yes, we just moved and renamed the file at the same time.

# By using the remove() method we can remove the file.
# For example, if we want to remove the 3.txt file from the blogs directory.
# To do this, we can write the following code:

import os

os.remove('./blogs/3.txt')
Comment

PREVIOUS NEXT
Code Example
Python :: ERROR: Target path exists but is not a directory, will not continue. 
Python :: 1043 uri solution 
Python :: ex: git push new local repo 
Python :: Fill NaN with the first valid value starting from the rightmost column, then extract first column 
Python :: Combine first and last 3 columns into new dataframe 
Python :: Open AI Call 
Python :: create horizontal descriptives table pandas 
Python :: basic decorator example 
Python :: Creaing your own functions 
Python :: change between two python 3 version in raspberrry pi 
Python :: kivy bind when text changes 
Python :: como tornar uma string numa lista 
Python :: i type nano in python and o get error 
Python :: provide a script that prints the sum of every even numbers in the range [0; 100]. 
Python :: online python formatter and compiler 
Python :: houghlinesp python stackoverflow 
Python :: python console ending multiline input 
Python :: python - dataframe columns is a list - drop 
Python :: does python have a end of line symbol 
Python :: get last item in array python 
Python :: how to get entitys of word using pytho nlp 
Python :: Return an RDD created by coalescing all elements within each partition into a list. 
Python :: somma array python 
Python :: how to xor two element in python 
Python :: drop duplicates pandas considering lowercase 
Python :: dataframe remove first row 
Python :: print python setencode 
Python :: not to display column tree odoo 8 
Python :: python list comprehension with filter example 2 
Python :: Get the first item from an iterable that matches a condition 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =