1

As the title kind of asks; it's a relatively straight forward one but I couldn't find anything with my google-fu or on SO already, with the way I'm wording it anyways.

The long and the short is; I have a few different csv files in a Network Drive for work that I want to either:

  • Read data from to put into a dataframe
  • Copy file to a temp location

Every time I run my script, if another user on the network has the file open, I'll receive a permission error as it's "In use" by another user.

Is there anyway around this at all? the people in the file 99.9% of the are purely reading the file and not altering the data, but I can't seem to find a way around just a pure "Read" or "Copy as is" solution.

Any insight or advice would be appreciated, as I'm sure I'm not the only one.

Basic copy of my code as below:

import os
import shutil
import pandas as pd

#Destination
dst = '//network/drive_a/destination/'

#Source Locations
src =  r'//network/drive_b/*.xlsx'

# Get latest file in source
list_of_files = glob.glob(src)
new_file = max(list_of_files, key=os.path.getctime)

#read into dataframe
df = pd.read_excel(new_file)

#add status flag in dataframe
df.loc[:,'status'] = 'Exception'
df = df.reset_index(drop=True)

Or if I was copying the file, instead of the dataframe it would be:

#Find Latest file and copy
list_of_files = glob.glob(src)
new_file = max(list_of_files, key=os.path.getctime)
copy_file = shutil.copy2(new_file, dst)```
Shalzar
  • 13
  • 3
  • maybe [this](https://stackoverflow.com/questions/28356985/python-library-or-code-to-read-already-open-excel-file) or [this](https://stackoverflow.com/questions/35743905/pd-read-excel-throws-permissionerror-if-file-is-open-in-excel) – Matt Aug 09 '21 at 13:53
  • I'll definitely have to check those out, thank you for linking these...I gotta make my terms simpler :) – Shalzar Aug 10 '21 at 08:43

0 Answers0