How to use pathlib for a nas drive path in python

Viewed 38

There are files in nas drive and i want find the files and iterate each file.below is variable i m declaring pathx = path.Path('////NAS01042pn/data/FILESHARE/Jobs/ASM_File/Inbound/NONPROD/AWE_Test')

for path in os.scandir(pathx):
if path.is_file():
    print(path.name)
    filename = path.name
    if('ASM_Test_MEMBERS_' in path.name):
    if(True):
        fileListCheck = path.name.split('_')
        lastString = fileListCheck[-1]
        firstLastStringList = lastString.split('.')

but if i do like this i get error as the mentioned path doesnt exist. Also tried below method- #pathx = b'\\NAS01042pn\data\OPTUM_HC_FILESHARE\Talend_Job_Conductor\ASM_Operations\Inbound\NONPROD\Test' but here it stores as bytes and i get error as firstLastStringList cannot be bytes. Any suggestions how to use pathlib for nas drive.

1 Answers

It worked for me from a windows machine. I changed forward slash to backward slash with escape:

import path as path

pathx = path.Path('\\\\NAS01042pn\\data\\FILESHARE\\Jobs\\ASM_File\\Inbound\\NONPROD\\AWE_Test')
Related