我有一个文件路径字符串列表.我想以拆分文件路径字符串的列表结束.
之前:
path_list = ['path/to/file.txt', 'path/to/another/file.txt', 'another/path/to/afile.txt', 'justafile.txt']
所需输出:
[['path/', 'to/', 'file.txt'],
['path/', 'to/', 'another/', 'file.txt'],
['another/', 'path/', 'to/', 'afile.txt'],
['justafile.txt']]
到目前为止,我已经try 了以下几种方法:
path_list = ['path/to/file.txt', 'path/to/another/file.txt', 'another/path/to/afile.txt', 'justafile.txt']
new_list = []
for i in path_list:
new_list.append(Path(i).parts)
它很接近,但丢失了斜杠(/).