Python move a file 🗃️

preview_player
Показать описание
Python move replace file tutorial example explained

#python #move #replace #file

import os

try:
print("There is already a file there")
else:
print(source+" was moved")
except FileNotFoundError:
print(source+" was not found")

Рекомендации по теме
Комментарии
Автор

import os

source =
destination =

try:
if os.path.exists(destination):
print("There is already a file there")
else:
os.replace(source, destination)
print(source+" was moved")
except FileNotFoundError:
print(source+" was not found")

BroCodez
Автор

0:22 thank you for making that very clear

ianfawknotson
Автор

making my part to defeat the algorithm!

hermenenjildojuarez
Автор

getting error:

OSError: [WinError 17] The system cannot move the file to a different disk drive: -

looks like you can't move a file from etc d:\ -> c: disk with this method, need to use something like shutil instead

import os
import shutil

shutil.move

source = "movetest.txt"
destination =

try:
if os.path.exists(destination):
print("There is already a file there")
else:
shutil.move(source, destination)
print(source+" was moved")
except FileNotFoundError:
print(source+" was not found")

kladzen
Автор

I'm trying to move the file but it always print "There is always a file there" although there isn't one.

SageSeeker
Автор

cant we use shutil.move ? I tried it n it worked. is there any difference ?😊

shavindasilva
Автор

Pycharm doesn't seem to detect the file. Keeps saying it was not found

hiushiko
Автор

Amazing tutorial !! full of great information, thx

piotrkopcewicz
Автор

finally 😂 after trying so much modules

circle
Автор

Thanks for the video,
What about if I'd want to move many files?
How could I do it?

JaimeRodriguez-sbxq
Автор

os.replace doesn't work for me instead, i use shutil.move from the shutil module if anyone knows tell me

AM-qxjt
Автор

Access is denied, even tho i tried to run the cmd as adminstrator it's still saying the same thing

spac
Автор

i was wonder if i wanted to move a folder on someone else's computer for instaltion purposes, how would i make that so, the user is different for every computer

ERFaep
Автор

i failed to make the script work but still a nice video i learned something :)

hul
Автор

Do anyone know how can i do to detect all the files with the same extension?
Then i would like to move them all(maybe using a for loop).

HandleNotAvailabIe
Автор

In my project I nees to move files from a shared folder. How can I do this ?

tiagohenriques
Автор

how can i define user's name with a value

metalhead-
Автор

This is interesting: PyCharm refuses to move file to another disk drive.

hostvind
Автор

I would like the codes sir.. ( You know what i'm talking about )

unbreakable