Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issue with os.rename
#1
Hello experts,

I am facing this issue with os.rename

I have multiple scripts in my Jupyter notebook, and at some point I need to move some files to the "processed" folder.
When I run below code
import os
post_id='66ec21db97'
for s,n in majle.items():
    if n==post_id:
        d = re.sub(r'CCC\\',r'CCC\\processed\\',s)
        print('src - {}'.format(s))  
        print('dst - {}'.format(d))        
#         os.rename(s, d)
I am getting correct output:

src - C:\Users\marcin\Desktop\CCC\_External_ New Topic_ _Visio process map for customer account creation_ in Receivables & Collections.msg
dst - C:\Users\marcin\Desktop\CCC\processed\_External_ New Topic_ _Visio process map for customer account creation_ in Receivables & Collections.msg

But when I uncomment last line - os.rename(s, d), I am getting this error with double backslashes in my path:

Error:
PermissionError Traceback (most recent call last) <ipython-input-11-b0460c8bfdbc> in <module> 6 print('src - {}'.format(s)) 7 print('dst - {}'.format(d)) ----> 8 os.rename(s, d) PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\marcin\\Desktop\\CCC\\_External_ New Topic_ _Visio process map for customer account creation_ in Receivables & Collections.msg' -> 'C:\\Users\\marcin\\Desktop\\CCC\\processed\\_External_ New Topic_ _Visio process map for customer account creation_ in Receivables & Collections.msg'
Is this the issue with backshales or some previous script indeed is blocking the file?
If so, how to release the the file?
Reply


Messages In This Thread
Issue with os.rename - by malinowy - Jun-25-2019, 04:05 PM
RE: Issue with os.rename - by nilamo - Jun-25-2019, 04:23 PM
RE: Issue with os.rename - by malinowy - Jun-25-2019, 04:46 PM
RE: Issue with os.rename - by malinowy - Jun-26-2019, 08:55 AM
RE: Issue with os.rename - by malinowy - Jul-01-2019, 11:53 AM

Forum Jump:

User Panel Messages

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