我编写Python脚本来复制文件; 不幸的是它因为文件名太长(> 256)而一直失败.无论如何要处理这个问题?
我正在使用Python 2.5.4和Windows XP.
干杯,
这给我一个短路径(DOS约定)(在Windows上):
import tempfile
tempDir = tempfile.mkdtemp()
print tempDir
Output >>> c:\users\admini~1\appdata\local\temp\tmpf76unv
Run Code Online (Sandbox Code Playgroud)
请注意admini~1.
如何将其转换为完整路径?例如C:\ users\administrator\appdata ...
这是执行的截图:
如您所见,错误显示目录"JSONFiles/Apartment/Rent/dubizzleabudhabiproperty"不存在.
但是看看我的文件,请:
文件夹肯定在那里.
代码
self.file = open("JSONFiles/"+ item["category"]+"/" + item["action"]+"/"+ item['source']+"/"+fileName + '.json', 'wb') # Create a new JSON file with the name = fileName parameter
line = json.dumps(dict(item)) # Change the item to a JSON format in one line
self.file.write(line) # Write the item to the file
Run Code Online (Sandbox Code Playgroud)
当我将文件名更改为较小的文件名时,它可以正常工作,因此问题在于路径的长度.请问是什么解决方案?