Python Forum
Cannot copy file to another location
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cannot copy file to another location
I am trying to copy a file to another location in Python 2.7 and I am getting error all the time saying no such file or directory. The file is actually present because when I do print fname it does print out the correct filename in that for loop. If you know any other way to copy file to a destination location please do tell me.

import os
import shutil

currDir = os.curdir
destDir = 'C:\Users\\user1\Documents\PET'
for dirName, subDirList, fileList in os.walk(currDir):
    for fname in fileList:
        if fname == '':
            shutil.copyfile(fname, destDir)
        if fname == 'GMB.fluf':
            shutil.copyfile(fname, destDir)
for shutil.copyfile you specify the source and destination FILE NAMEs. Your command is trying to replace the PED directory with some file.

Possibly Related Threads…
Thread Author Replies Views Last Post
  is it possible to copy image from email and place into excel file? cubangt 3 417 Nov-30-2022, 05:11 PM
Last Post: snippsat
  Please help me [copy and paste file from src to dst] midomarc 2 434 Nov-24-2022, 10:13 PM
Last Post: midomarc
  Changing file location azizrasul 6 462 Sep-28-2022, 01:01 AM
Last Post: azizrasul
  Copy column from one existing excel file to another file mkujawsk 0 3,403 Apr-14-2021, 06:33 PM
Last Post: mkujawsk
  find the header location in a .bin file without reading the whole file at a time SANJIB 0 1,686 Mar-05-2021, 04:08 PM
Last Post: SANJIB
  Failing to copy file from a network to a local drive tester_V 4 4,596 Jan-20-2021, 07:40 AM
Last Post: tester_V
  Copy mp3 file multiple times and rename Mar10 4 2,804 Sep-23-2020, 01:09 AM
Last Post: Mar10
  Python Cut/Copy paste file from folder to another folder rdDrp 4 3,912 Aug-19-2020, 12:40 PM
Last Post: rdDrp
  copy content of text file with three delimiter into excel sheet vinaykumar 0 1,616 Jul-12-2020, 01:27 PM
Last Post: vinaykumar
  copy/pasting in excel WHILE keep file format zarize 0 1,472 Jun-23-2020, 03:51 PM
Last Post: zarize

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020