我在linux服务器上有文件,并且文件名由于中间的\ r字符而损坏。我无法在Windows上使用WinScp或Filezilla下载这些文件。
此外,我无法在python中重命名或正确处理它们。根据命令
files = os.listdir("2014/")
我得到了这个清单。
['16963_6_iris2570_20150110_052515\r_172518.gpx', '29174_3_Sunnam0223_20150114_0 10833\r_130835.gpx', '35767_3_samsi2_20150117_035045\r_155047.gpx', '36581_4_kix ing_20150117_045424\r_165425.gpx', '33383_4_rnrghk10kr_20150117_101618\r_101619. gpx']
根据命令:
file1 = files[0]
输出: _172518.gpxs2570_20150110_052515
然后我尝试替换\ r
file2 = files[0].replace('\r', '')
输出: 16963_6_iris2570_20150110_052515_172518.gpx
很好,但是当我尝试重命名时:
os.rename("2014/"+file1, "2014/"+file2)
f = open(file2, "r")
data = f.readlines()
f.close()
输出:
Traceback (most recent call last):
File "test.py", line 25, in <module>
f = open(file2, "r")
IOError: [Errno 2] No such file or directory: '29174_3_Sunnam0223_20150114_010833_130835.gpx'
你试过了吗:
f = open("2014/"+file2, "r")
在上面的示例代码中,您在重命名中包含了2014文件夹名称,但未在公开通话中包含。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句