简体   繁体   中英

How to use pathlib for a nas drive path in python

There are files in nas drive and i want find the files and iterate each file.below is variable im 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.

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM