Python 重写窗口文件名长度时连接文件路径的问题

Python 重写窗口文件名长度时连接文件路径的问题,python,pandas,concatenation,glob,Python,Pandas,Concatenation,Glob,我在使用Python3.7连接服务器目录路径时遇到问题。我有它的工作,但需要在这段代码(如讨论),以便覆盖windows控制器路径上的最大260个字符的限制 \\\\?\\UNC 只是看起来语法不正确。在未添加UNC的情况下,下面的函数正在工作(返回匹配项)。但当它遇到一个长文件名时,程序就会崩溃 def file_path(data): latest_file_list = [] for index, row in data.iterrows(): log1

我在使用Python3.7连接服务器目录路径时遇到问题。我有它的工作,但需要在这段代码(如讨论),以便覆盖windows控制器路径上的最大260个字符的限制

\\\\?\\UNC
只是看起来语法不正确。在未添加UNC的情况下,下面的函数正在工作(返回匹配项)。但当它遇到一个长文件名时,程序就会崩溃

def file_path(data):
    latest_file_list = []
    for index, row in data.iterrows():
        log1 = row['Log number 2001']
        file_path = row['file_path_short']
        location = r"" +str(file_path)+ "*\*\*\*\**\*"+ str(log1) +"*.pdf"
        # check file on drive
        list_of_files = glob.glob(location, recursive=True)
位置相当于:

\\servername\...
下面的代码是我正在测试的修复字符限制的代码,它不会给出错误,但也不会返回任何匹配项

location2 = r"\\\\?\\UNC" +str(file_path)+ "*\*\*\*\**\**\*"+ str(log1) +"*.pdf"
位置2相当于

\\?\UNC\servername\...
我试过用u和r作为前缀,但没有用

有人能给我一些指导吗?有更好/更简单的解决方案吗

编辑

我也尝试过这个方法,它对短文件名有效,但对长文件名给出[WinError 3]错误

import os
location3 = os.path.join(r"\\\\?\\UNC", str(file_path), "*\*\**", "*"+ str(log1) +"*" +".pdf" )
Edit2

因此,我一直在使用以下代码处理pathlib:

from pathlib import Path
location4 = Path(r"\\\\?\\UNC", str(file_path), "*\*\**", "*"+ str(log1) +"*" +".pdf" )

但是我现在得到了这个错误
TypeError:expected string或bytes-like-object

,所以我最终的工作方式是使用映射文件路径。我将要访问的网络驱动器映射到我的Z驱动器。我用这个代码访问它。它可以正常工作,只是我必须确保在运行代码之前先访问了驱动器

location = "\\\\?\\Z:" +str(file_path)+ "*\*\*\*\**\*"+ str(log1) +"*.pdf"

所以我已经从
\\server\folder1\folder2\folder3..
转移到
Z:\folder2\folder3..
所以当连接在一起时
\\\\?\\Z:\folder2\folder3..

你试过使用Python3的内置pathlib吗@Hrabal我尝试过os.path.join,但似乎无法使其正常工作。