文件路径,转义符和OS库输入(不接受我的文件路径)

时间:2018-12-05 17:45:22

标签: python

此reddit线程将对项目进行一些解释,并为我要完成的工作提供上下文。本质上,我正在比较pdf,使用名称以外的名称来查看是否存在重复项。这是因为我的数据集中的所有pdf都有唯一的名称,但是在内容上还是一样的。寻找并销毁副本。我仍在这个项目的寻求部分。

https://www.reddit.com/r/Python/comments/a337qv/finding_unique_pdfs_in_a_folder_need_info_on_how/

我决定先尝试比较文件大小,然后再尝试其他操作,然后再看一下会发现什么。我认为这是一种简单的第一种方法,但是由于某种原因,os库不喜欢我向它提供文件路径字符串的方式。我尝试过尽一切可能来操纵它,但没有骰子。

我经过检查,确认文件位于我要进入的文件夹中。

因此,这是我想像的工作流程。我查询了可能包含重复项的图形,并将其另存为excel文件。我将该文件另存为csv文件,所以如果我搞砸工作表,就不会搞砸我的数据。另外,我还提供了一种使用熊猫将csv文件列转换为列表的快速方法。

Here is a screen shot of the csv file

在下面的代码中,您可以看到我列出了包含所有这些列的列表。列表中的所有数据都是字符串。描述不是很严格,但是“找到”和“名称”列(串联时)组成文件路径和文件名。我制作了一个新的组合字符串列表,即文件路径+文件,以便可以比较它的大小。

我真的希望有一种方法可以通过csv文件或python在列表中操纵该路径。

这是运行代码时出现的错误。

https://imgur.com/a/d9P7g0e

C:\ Users \ 27659 \ Desktop \ PycharmProjects \ sort_unique_profiles \ venv \ Scripts \ python.exe“ C:/ Users / 27659 / Desktop / PycharmProjects / sort_unique_profiles /比较并标记files.py”

same item in list

Traceback (most recent call last):

    File "C:/Users/27659/Desktop/PycharmProjects/sort_unique_profiles/Compare and mark files.py", line 19, in <module>

        if os.path.getsize(full_file_list[i]) == os.path.getsize(full_file_list[k]) and i == k:

    File "C:\Users\27659\AppData\Local\Programs\Python\Python37-32\lib\genericpath.py", line 50, in getsize

        return os.stat(filename).st_size

FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\\WS\\WS\\Aspire\\CA & AW\\7205\\AW\\85-7535-01.pdf'

Process finished with exit code 1

'

这是代码

import pandas as pd
import os


main_df = pd.read_csv("C://Users//27659//Desktop//Unique Wood Profiles.csv")

drawing_number_list = main_df['Name'].tolist()
description_list = main_df['Description'].tolist()
found_in_list = main_df['Found In'].tolist()
full_file_list = ['placeholder']

for i in range(0, len(drawing_number_list)):
    full_file_list.append(found_in_list[i] + drawing_number_list[i] + '.pdf')

del full_file_list[0]

for i in range(0, len(full_file_list)):
    for k in range(0, len(full_file_list)):
        if os.path.getsize(full_file_list[i]) == os.path.getsize(full_file_list[k]) and i == k:
            print('same item in list')
        elif os.path.getsize(full_file_list[i]) == os.path.getsize(full_file_list[i]):
            print('oh bugger')
        else:
            print('thumbs up')

'

编辑:

All files: ['C:\\WS\\WS\\Aspire\\CA & AW\\7205\\AW\\85-7534-01.pdf', 'C:\\WS\\WS\\Aspire\\CA & AW\\7205\\AW\\85-7535-01.pdf', 'C:\\WS\\WS\\Aspire\\CA & AW\\7205\\AW\\85-7394-01.pdf', 'C:\\WS\\WS\\Aspire\\CA & AW\\7205\\AW\\85-7740-01.pdf', 'C:\\WS\\WS\\Aspire\\CA & AW\\7205\\AW\\85-7886-01.pdf', 'C:\\WS\\WS\\Aspire\\CA & AW\\7205\\AW\\85-7821-01.pdf', 'C:\\WS\\WS\\Aspire\\CA & AW\\7205\\AW\\85-7392-01.pdf', 'C:\\WS\\WS\\Aspire\\CA & AW\\7205\\Bow, Bay & Garden\\P0035400.pdf', 'C:\\WS\\WS\\Aspire\\CA & AW\\7205\\CA\\45-05151.pdf', 'C:\\WS\\WS\\Aspire\\CA & AW\\7205\\CA\\45-05154.pdf', 'C:\\WS\\WS\\Aspire\\CA & AW\\7205\\CA\\45-05149.pdf', 'C:\\WS\\WS\\Aspire\\CA & AW\\7205\\Grilles\\60-4623-02.pdf', 'C:\\WS\\WS\\Aspire\\CA & AW\\7205\\Grilles\\85-7723-01.pdf', 'C:\\WS\\WS\\Aspire\\CA & AW\\7205\\Mull, Stack & Trim\\08-W8092.pdf', 'C:\\WS\\WS\\Aspire\\CA & AW\\7205\\Mull, Stack & Trim\\85-7611-01.pdf', 'C:\\WS\\WS\\Aspire\\CA & AW\\POCKET 7206\\CA\\85-8287-01.pdf', 'C:\\WS\\WS\\Aspire\\DH\\7105\\DH\\60-12966-01.pdf', 'C:\\WS\\WS\\Aspire\\DH\\7105\\DH\\85-8444-01.pdf', 'C:\\WS\\WS\\Aspire\\DH\\7105\\DH\\60-12931-01.pdf', 'C:\\WS\\WS\\Aspire\\DH\\7105\\DH\\60-12986-01.pdf', 'C:\\WS\\WS\\Aspire\\DH\\7105\\DH\\60-12967-01.pdf', 'C:\\WS\\WS\\Aspire\\DH\\7105\\DH\\60-12675-01.pdf', 'C:\\WS\\WS\\Aspire\\DS\\7305\\Window Std Unit\\85-8047-01.pdf', 'C:\\WS\\WS\\Aspire\\DS\\7305\\Window Std Unit\\85-7604-01.pdf', 'C:\\WS\\WS\\Aspire\\HGD\\1.75 In HGD IS_7502\\1W\\08-0003-W2403.pdf', 'C:\\WS\\WS\\Aspire\\HGD\\1.75 In HGD IS_7502\\1W\\08-1504-02.pdf', 'C:\\WS\\WS\\Aspire\\HGD\\1.75 In HGD IS_7502\\DS Tran Insert\\60-0239-01.pdf', 'C:\\WS\\WS\\Aspire\\HGD\\1.75 In HGD IS_7502\\Grilles\\60-0057-01.pdf', 'C:\\WS\\WS\\Aspire\\HGD\\1.75 In HGD IS_7502\\Grilles\\60-0036-01.pdf', 'C:\\WS\\WS\\Aspire\\HGD\\1.75 In HGD IS_7502\\Mull, Stack, & Trim\\45-03943.pdf', 'C:\\WS\\WS\\Aspire\\HGD\\1.75 In HGD IS_7502\\Tech Data & Mull C:\\60-2922-01.pdf', 'C:\\WS\\WS\\Aspire\\HGD\\1.75 In HGD IS_7502\\Tech Data & Mull C:\\60-3346-01.pdf', 'C:\\WS\\WS\\Aspire\\SGD\\1W\\70-6439-01.pdf', 'C:\\WS\\WS\\Aspire\\SGD\\1W\\85-7624-01.pdf', 'C:\\WS\\WS\\Aspire\\SGD\\1W\\70-6656-01.pdf', 'C:\\WS\\WS\\Aspire\\SGD\\1W\\70-6374-01.pdf', 'C:\\WS\\WS\\Aspire\\SGD\\1W\\60-10478-01.pdf', 'C:\\WS\\WS\\Aspire\\SGD\\1W\\70-6604-01.pdf', 'C:\\WS\\WS\\Aspire\\SGD\\2W\\70-6655-01.pdf', 'C:\\WS\\WS\\Collections\\CA & AW\\CA_6206\\CA - French_6206\\60-6264-01.pdf', 'C:\\WS\\WS\\Collections\\CA & AW\\CA_6206\\CA - Mull, Stack & Trim_6206\\60-7136-01.pdf', 'C:\\WS\\WS\\Collections\\CA & AW\\CA_6206\\CA - Mull, Stack & Trim_6206\\60-5946-01.pdf', 'C:\\WS\\WS\\Collections\\CA & AW\\CA_6206\\CA - Sash Set Pict, Tran, Fixed_6206\\60-5473-01.pdf', 'C:\\WS\\WS\\Collections\\CA & AW\\CA_6206\\CA - Sash Set Pict, Tran, Fixed_6206\\60-5504-01.pdf', 'C:\\WS\\WS\\Collections\\CA & AW\\CA_6206\\CA - Sash Set Pict, Tran, Fixed_6206\\60-6290-01.pdf', 'C:\\WS\\WS\\Collections\\CA & AW\\CA_6206\\CA - Sash Set Pict, Tran, Fixed_6206\\60-5503-01.pdf', 'C:\\WS\\WS\\Collections\\CA & AW\\CA_6206\\CA - Sash Set Pict, Tran, Fixed_6206\\60-5474-01.pdf', 'C:\\WS\\WS\\Collections\\CA & AW\\CA_6206\\CA - Screens & Storms_6206\\60-6031-01.pdf', 'C:\\WS\\WS\\Collections\\CA & AW\\CA_6206\\CA - Screens & Storms_6206\\60-6033-01.pdf', 'C:\\WS\\WS\\Collections\\CA & AW\\CA_6206\\CA_6206-files\\60-5491-01.pdf', 'C:\\WS\\WS\\Collections\\CA & AW\\CA_6206\\CA_6206-files\\60-5588-01.pdf', 'C:\\WS\\WS\\Collections\\HGD\\6502\\Mull, Stack & Trim\\08-W5035X.pdf', 'C:\\WS\\WS\\Collections\\HGD\\6503\\1Wide\\70-1889-01.pdf', 'C:\\WS\\WS\\Collections\\HGD\\6503\\1Wide\\70-1737-01.pdf', 'C:\\WS\\WS\\Collections\\HGD\\6503\\1Wide\\70-2159-01.pdf', 'C:\\WS\\WS\\Collections\\HGD\\6504\\IS - 1Wide\\70-3317-01.pdf', 'C:\\WS\\WS\\Collections\\HGD\\6504\\IS-Sidelite\\70-4158-01.pdf', 'C:\\WS\\WS\\Collections\\HGD\\6505\\IS - 1Wide\\85-1802-01.pdf', 'C:\\WS\\WS\\Collections\\HGD\\6505\\IS - 1Wide\\85-1803-01.pdf', 'C:\\WS\\WS\\Collections\\HGD\\6505\\IS - 1Wide\\85-1800-01.pdf', 'C:\\WS\\WS\\Collections\\HGD\\6505\\IS - 1Wide\\85-1805-01.pdf', 'C:\\WS\\WS\\Collections\\HGD\\6505\\IS - 1Wide\\85-1804-01.pdf', 'C:\\WS\\WS\\Collections\\HGD\\6505\\IS - 1Wide\\85-1810-01.pdf', 'C:\\WS\\WS\\Collections\\HGD\\6505\\IS - 1Wide\\85-1811-01.pdf', 'C:\\WS\\WS\\Collections\\HGD\\6505\\IS - 3Wide Triple\\85-1812-01.pdf', 'C:\\WS\\WS\\Collections\\HGD\\6505\\IS - DS Sidelite Boxed\\85-1813-01.pdf', 'C:\\WS\\WS\\Collections\\HGD\\6605\\OS - 1Wide\\85-1806-01.pdf', 'C:\\WS\\WS\\Collections\\HGD\\6605\\OS - 1Wide\\85-1808-01.pdf', 'C:\\WS\\WS\\Collections\\HGD\\6605\\OS - 2Wide\\85-1809-01.pdf', 'C:\\WS\\WS\\Collections\\HGD\\6605\\OS - DS Sidelite Boxed\\85-1814-01.pdf', 'C:\\WS\\WS\\Collections\\Hung Window\\Collections - DH_6107\\Dbl-Hung\\60-5654-01.pdf', 'C:\\WS\\WS\\Collections\\Hung Window\\Collections - DH_6107\\Dbl-Hung\\60-6547-01.pdf', 'C:\\WS\\WS\\Collections\\Hung Window\\Collections - DH_6107\\Dbl-Hung\\60-6582-01.pdf', 'C:\\WS\\WS\\Collections\\Hung Window\\Collections - DH_6107\\Dbl-Hung\\60-6846-01.pdf', 'C:\\WS\\WS\\Collections\\Hung Window\\Collections - DH_6107\\Dbl-Hung\\60-6543-01.pdf', 'C:\\WS\\WS\\Collections\\Hung Window\\Collections - DH_6107\\Dbl-Hung\\60-6548-01.pdf', 'C:\\WS\\WS\\Collections\\Hung Window\\Collections - DH_6107\\Dbl-Hung\\60-5850-01.pdf', 'C:\\WS\\WS\\Collections\\Hung Window\\Collections - DH_6107\\Dbl-Hung\\60-6542-01.pdf', 'C:\\WS\\WS\\Collections\\Hung Window\\Collections - DH_6107\\Dbl-Hung\\60-1684-01.pdf', 'C:\\WS\\WS\\Collections\\Hung Window\\Collections - DH_6107\\Dbl-Hung\\60-5865-01.pdf', 'C:\\WS\\WS\\Collections\\Hung Window\\Collections - DH_6107\\Dbl-Hung\\60-6605-01.pdf', 'C:\\WS\\WS\\Collections\\Hung Window\\Collections - DH_6107\\Mull, Stack & Trim\\60-5588-02.pdf', 'C:\\WS\\WS\\Collections\\Hung Window\\Collections - DH_6107\\Sash Set Pict, Tran, Fixed\\60-6837-01.pdf', 'C:\\WS\\WS\\Collections\\Hung Window\\Collections - DH_6107\\Sash Set Pict, Tran, Fixed\\60-6839-01.pdf', 'C:\\WS\\WS\\Collections\\Hung Window\\Collections - DH_6107\\Sash Set Pict, Tran, Fixed\\60-6849-01.pdf', 'C:\\WS\\WS\\Collections\\Hung Window\\Collections - DH_6107\\Sash Set Pict, Tran, Fixed\\60-7100-01.pdf', 'C:\\WS\\WS\\Collections\\Hung Window\\Collections - SH_6106\\SH_6106\\60-6557-01.pdf', 'C:\\WS\\WS\\Collections\\Hung Window\\Collections - SH_6106\\SH_6106\\60-6552-01.pdf', 'C:\\WS\\WS\\Collections\\Hung Window\\Collections - SH_6106\\SH_6106\\60-6551-01.pdf', 'C:\\WS\\WS\\Collections\\SGD\\Collections - SGD_6708\\2Wide\\70-0337-01.pdf', 'C:\\WS\\WS\\Collections\\SGD\\Collections - SGD_6708\\2Wide\\60-0851-01.pdf', 'C:\\WS\\WS\\Collections\\SGD\\Collections - SGD_6708\\3Wide\\60-4013-01.pdf', 'C:\\WS\\WS\\Collections\\SGD\\Collections - SGD_6708\\4Wide\\70-0507-01.pdf', 'C:\\WS\\WS\\Contemporary\\FRENCH CA\\8218\\85-7906-01.pdf', 'C:\\WS\\WS\\Contemporary\\FRENCH CA\\8218\\85-10134-01.pdf', 'C:\\WS\\WS\\Contemporary\\FRENCH CA\\8218\\85-10821-02.pdf', 'C:\\WS\\WS\\Contemporary\\FRENCH CA\\8218\\85-8084-01.pdf', 'C:\\WS\\WS\\Contemporary\\HGD\\2.25 IS-CTMP 8517\\1W\\85-10889-01.pdf', 'C:\\WS\\WS\\Contemporary\\HGD\\2.25 IS-CTMP 8517\\1W\\85-2654-01.pdf', 'C:\\WS\\WS\\Contemporary\\HGD\\2.25 IS-CTMP 8517\\1W\\85-10320-01.pdf', 'C:\\WS\\WS\\Contemporary\\HGD\\2.25 IS-CTMP 8517\\2W\\85-11892-02.pdf', 'C:\\WS\\WS\\Contemporary\\HGD\\2.25 IS-CTMP 8517\\Mull, Stack & Trim\\85-12005-01.pdf', 'C:\\WS\\WS\\Contemporary\\HGD\\2.25 IS-CTMP 8517\\Mull, Stack & Trim\\85-12006-01.pdf', 'C:\\WS\\WS\\Contemporary\\HGD\\2.25 IS-CTMP 8517\\Mull, Stack & Trim\\85-12007-01.pdf', 'C:\\WS\\WS\\Contemporary\\HGD\\2.25 IS-CTMP 8517\\Mull, Stack & Trim\\85-12008-01.pdf', 'C:\\WS\\WS\\Contemporary\\HGD\\2.25 OS-CTMP 8617\\1W\\08-0006-C2403.pdf', 'C:\\WS\\WS\\Contemporary\\HGD\\OS Bi-fold 8623\\2W\\45-03268.pdf', 'C:\\WS\\WS\\Contemporary\\HGD\\OS Bi-fold 8623\\2W\\45-04681.pdf', 'C:\\WS\\WS\\Contemporary\\PUSH OUT\\8217\\PUSH OUT FRENCH CA\\85-8182-01.pdf', 'C:\\WS\\WS\\Contemporary\\PUSH OUT\\8217\\PUSH OUT FRENCH CA\\85-8186-01.pdf', 'C:\\WS\\WS\\Contemporary\\PUSH OUT\\8217\\PUSH OUT FRENCH CA\\85-8059-01.pdf', 'C:\\WS\\WS\\Contemporary\\SGD\\1.75 Contemp Multi Slide 8720\\Pocket\\Bipart\\10W\\45-01468.pdf', 'C:\\WS\\WS\\Contemporary\\SGD\\1.75 Contemp Multi Slide 8720\\Pocket\\Bipart\\10W\\85-8748-01.pdf', 'C:\\WS\\WS\\Contemporary\\SGD\\1.75 Contemp Multi Slide 8720\\Pocket\\Bipart\\10W\\85-11969-01.pdf', 'C:\\WS\\WS\\Contemporary\\SGD\\1.75 Contemp Multi Slide 8720\\Pocket\\Bipart\\10W\\85-11138-01.pdf', 'C:\\WS\\WS\\Contemporary\\SGD\\1.75 Contemp Multi Slide 8720\\Pocket\\Bipart\\10W\\85-7951-01.pdf', 'C:\\WS\\WS\\Contemporary\\SGD\\1.75 Contemp Multi Slide 8720\\Pocket\\Bipart\\10W\\85-8941-01.pdf', 'C:\\WS\\WS\\Contemporary\\SGD\\1.75 Contemp Multi Slide 8720\\Pocket\\Bipart\\10W\\85-12079-01.pdf', 'C:\\WS\\WS\\Contemporary\\SGD\\1.75 Contemp Multi Slide 8720\\Pocket\\Single Dir\\3W\\45-01465.pdf', 'C:\\WS\\WS\\Contemporary\\SGD\\1.75 Contemp Multi Slide 8720\\Stacked\\Bipart\\10W\\45-01460.pdf', 'C:\\WS\\WS\\Contemporary\\SGD\\1.75 Contemp Sliding Patio 8717\\1W\\60-10452-01.pdf', 'C:\\WS\\WS\\Contemporary\\SGD\\1.75 Contemp Sliding Patio 8717\\1W\\08-2877-03.pdf', 'C:\\WS\\WS\\Contemporary\\SGD\\1.75 Contemp Sliding Patio 8717\\1W\\70-0360-02.pdf', 'C:\\WS\\WS\\Contemporary\\SGD\\1.75 Contemp Sliding Patio 8717\\1W\\85-11143-01.pdf', 'C:\\WS\\WS\\Contemporary\\SGD\\1.75 Contemp Sliding Patio 8717\\1W\\60-10454-01.pdf', 'C:\\WS\\WS\\Contemporary\\SGD\\1.75 Contemp Sliding Patio 8717\\1W\\60-10450-01.pdf', 'C:\\WS\\WS\\Contemporary\\SGD\\1.75 Contemp Sliding Patio 8717\\1W\\85-5529-01.pdf', 'C:\\WS\\WS\\Contemporary\\SGD\\2.25 Contemp Lift and Slide 8718\\Pocket\\Bipart\\10W\\85-8746-01.pdf', 'C:\\WS\\WS\\Contemporary\\SGD\\2.25 Contemp Lift and Slide 8718\\Pocket\\Bipart\\10W\\85-8394-01.pdf', 'C:\\WS\\WS\\Contemporary\\SGD\\2.25 Contemp Lift and Slide 8718\\Stacked\\Bipart\\10W\\45-01477.pdf', 'C:\\WS\\WS\\Custom Shield\\CA & AW\\8201\\AW\\311419.pdf', 'C:\\WS\\WS\\Custom Shield\\CA & AW\\8201\\AW\\08-W3004.pdf', 'C:\\WS\\WS\\Custom Shield\\CA & AW\\8201\\Bow, Bay & Garden\\09-W8096.pdf', 'C:\\WS\\WS\\Custom Shield\\CA & AW\\8201\\Bow, Bay & Garden\\70-3810-01.pdf', 'C:\\WS\\WS\\Custom Shield\\CA & AW\\8201\\CA\\311421.pdf', 'C:\\WS\\WS\\Custom Shield\\CA & AW\\8201\\CA\\311420.pdf', 'C:\\WS\\WS\\Custom Shield\\CA & AW\\8210\\AW\\60-6005-01.pdf', 'C:\\WS\\WS\\Custom Shield\\CA & AW\\8210\\AW\\60-6004-01.pdf', 'C:\\WS\\WS\\Custom Shield\\CA & AW\\8210\\AW\\60-3267.pdf', 'C:\\WS\\WS\\Custom Shield\\CA & AW\\8210\\AW\\70-0794-01.pdf', 'C:\\WS\\WS\\Custom Shield\\CA & AW\\8210\\AW\\70-0793-01.pdf', 'C:\\WS\\WS\\Custom Shield\\HGD\\851\\DS Tran Insert\\09-W5026-01.pdf', 'C:\\WS\\WS\\Custom Shield\\HGD\\851\\DS Tran Insert\\P0125800.pdf', 'C:\\WS\\WS\\Custom Shield\\HGD\\861\\DS Tran Insert\\60-2009-01.pdf', 'C:\\WS\\WS\\Custom Shield\\HGD\\861\\DS Tran Sim Sash\\60-1698-01.pdf', 'C:\\WS\\WS\\Custom Shield\\HGD\\861\\DS Tran Std Unit\\60-1694-01.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8103\\Cottage, Oriel, Sim Tran\\60-3483-01.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8103\\Cottage, Oriel, Sim Tran\\60-3258-01.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8103\\Cottage, Oriel, Sim Tran\\08-1005-01.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8103\\Cottage, Oriel, Sim Tran\\60-0638-01.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8103\\Cottage, Oriel, Sim Tran\\08-2039-02-03.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8103\\Cottage, Oriel, Sim Tran\\08-2041-02.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8103\\Cottage, Oriel, Sim Tran\\08-2038-02.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8103\\Cottage, Oriel, Sim Tran\\08-2049-02.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8103\\Cottage, Oriel, Sim Tran\\60-0642-01.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8103\\Sash Replacement\\60-2455-01.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8103\\Sash Replacement\\60-2458-01.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8103\\Sash Replacement\\08-1906-02.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8103\\Sash Replacement\\60-2453-01.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8103\\Sash Replacement\\60-2459-01.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8103\\Sash Replacement\\60-3516-01.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8103\\Sash Set Pic, Tran, Fixed\\08-2148-02.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8103\\Sash Set Pic, Tran, Fixed\\08-2147-02.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8108\\DH\\60-9949-01.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8108\\DH\\60-9858-01.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8108\\DH\\60-9017-01.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8108\\DH\\80-0581-01.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8108\\DH\\08-1897-02.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8108\\DH\\08-1025-01.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8108\\DH\\08-1892-02.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8108\\DH\\60-9021-01.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8108\\Sash Set Pic, Tran, Fixed\\08-2108-02.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8108\\Sash Set Pic, Tran, Fixed\\08-2106-02.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8112\\DH\\60-2487-01.pdf', 'C:\\WS\\WS\\Custom Shield\\Hung Window\\8112\\DH\\60-2493-01.pdf', 'C:\\WS\\WS\\Custom Shield\\Slide Window\\8403\\Double\\60-9350-01.pdf', 'C:\\WS\\WS\\Custom Shield\\Slide Window\\8403\\Double\\60-9359-01.pdf', 'C:\\WS\\WS\\Custom Shield\\Slide Window\\8403\\Double\\60-9353-01.pdf', 'C:\\WS\\WS\\Custom Shield\\Slide Window\\8403\\Double\\60-8003-01.pdf', 'C:\\WS\\WS\\Custom Shield\\Slide Window\\8403\\Double\\60-4026-01.pdf', 'C:\\WS\\WS\\LifeGuard IG Premium\\CA & AW\\1210\\Grilles\\60-5031-03.pdf', 'C:\\WS\\WS\\LifeGuard IG Premium\\CA & AW\\1210\\Mull, Stack & Trim\\85-8215-01.pdf', 'C:\\WS\\WS\\LifeGuard IG Premium\\CA & AW\\1210\\Mull, Stack & Trim\\85-7445-01.pdf', 'C:\\WS\\WS\\LifeGuard IG Premium\\CA & AW\\1210\\Sash Set Pict, Tran, Fixed\\85-8207-01.pdf', 'C:\\WS\\WS\\LifeGuard IG Premium\\CA & AW\\1210\\Screen-Storms Retractable Standard Interior\\85-9583-01.pdf', 'C:\\WS\\WS\\LifeGuard IG Premium\\DS\\1310\\Window Std Unit\\45-05175.pdf', 'C:\\WS\\WS\\LifeGuard IG Premium\\DS\\1310\\Window Std Unit\\45-05173.pdf', 'C:\\WS\\WS\\LifeGuard IG Premium\\DS\\1310\\Window Std Unit\\45-05171.pdf', 'C:\\WS\\WS\\LifeGuard IG Premium\\DS\\1310\\Window Std Unit\\85-8275-01.pdf', 'C:\\WS\\WS\\LifeGuard IG Premium\\French CA\\1212\\French CA\\45-02011.pdf', 'C:\\WS\\WS\\LifeGuard IG Premium\\French CA\\1212\\French CA\\85-8084-02.pdf', 'C:\\WS\\WS\\LifeGuard IG WS\\CA & AW\\1201\\AW\\09-w3002.pdf', 'C:\\WS\\WS\\LifeGuard IG WS\\CA & AW\\1201\\CA\\08-W2036.pdf', 'C:\\WS\\WS\\LifeGuard IG WS\\CA & AW\\1204\\CA\\60-12350-01.pdf', 'C:\\WS\\WS\\LifeGuard IG WS\\SGD\\SGD French_1702\\2W\\08-2930-03.pdf', 'C:\\WS\\WS\\LifeGuard WS\\CA & AW\\1206\\Sash Set Pic, Tran, Fixed\\60-10771-01.pdf', 'C:\\WS\\WS\\LifeGuard WS\\DS\\1302\\Window Std Unit\\85-5506-01.pdf', 'C:\\WS\\WS\\Mark Haven Alum Clad\\HGD\\8501\\DS Tran Std Unit\\100413.pdf', 'C:\\WS\\WS\\Mark Haven Alum Clad\\HGD\\8501\\DS Tran Std Unit\\100727.pdf', 'C:\\WS\\WS\\Mark Haven Alum Clad\\HGD\\8501\\Install, Replacement Catalog\\102379.pdf', 'C:\\WS\\WS\\Mark Haven Alum Clad\\HGD\\8501\\Mull, Stack & Trim\\80-0716-01.pdf', 'C:\\WS\\WS\\Mark Haven Alum Clad\\HGD\\8501\\Mull, Stack & Trim\\80-0714-01.pdf', 'C:\\WS\\WS\\Mark Haven Alum Clad\\HGD\\8501\\Mull, Stack & Trim\\80-0715-01.pdf', 'C:\\WS\\WS\\Mark Haven Alum Clad\\HGD\\8501\\Mull, Stack & Trim\\80-0718-01.pdf', 'C:\\WS\\WS\\Mark Haven Alum Clad\\HGD\\8509\\1W\\08-w5020.pdf', 'C:\\WS\\WS\\Mark Haven Alum Clad\\HGD\\8601\\DS Tran Std Unit\\100413.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH Pic\\1108 Single Glazed\\85-8398-01.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH Pic\\1108 Single Glazed\\85-8702-01.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH Pic\\1108 Single Glazed\\85-8701-01.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH Pic\\1108 Single Glazed\\85-7154-01.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH Pic\\1108 Single Glazed\\85-9136-01.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH Pic\\1108 Single Glazed\\85-7509-01.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH Pic\\1108 Single Glazed\\85-8428-01.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH Pic\\1108 Single Glazed\\85-7276-01.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH Pic\\1108 Single Glazed\\85-7787-01.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH Pic\\1108 Single Glazed\\85-7523-01.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH Pic\\1108 Single Glazed\\85-7196-02.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH Pic\\1108 Single Glazed\\85-7329-01.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH Tran\\1110 Single Glazed\\85-8031-01.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH Tran\\1110 Single Glazed\\85-8042-01.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH Tran\\1110 Single Glazed\\85-8384-01.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH\\1104 IG\\45-04721.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH\\1104 IG\\85-12152-01.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH\\1104 IG\\85-12154-01.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH\\1104 IG\\85-12152-02.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH\\1104 IG\\85-12109-01.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH\\1104 IG\\85-10647-01.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH\\1104 IG\\85-7318-01.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH\\1104 IG\\85-7206-01.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH\\1104 IG\\85-7206-02.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH\\1104 IG\\85-9116-01.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH\\1104 IG\\85-7441-01.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH\\1104 IG\\85-10977-01.pdf', 'C:\\WS\\WS\\Premium Coastal\\DH\\1105 Single Glazed\\45-00775.pdf', 'C:\\WS\\WS\\Premium\\CA & AW\\8211\\AW\\85-8437-01.pdf', 'C:\\WS\\WS\\Premium\\CA & AW\\8211\\EB, Segment\\85-8434-01.pdf', 'C:\\WS\\WS\\Premium\\CA & AW\\8211\\EB, Segment\\85-8354-01.pdf', 'C:\\WS\\WS\\Premium\\CA & AW\\8211\\Special Shapes\\85-7622-01.pdf', 'C:\\WS\\WS\\Premium\\DH Pic\\POCKET PIC 8119\\60-12888-01.pdf', 'C:\\WS\\WS\\Premium\\DH\\8109\\DH\\85-7614-01.pdf', 'C:\\WS\\WS\\Premium\\DH\\8109\\DH\\85-7366-01.pdf', 'C:\\WS\\WS\\Premium\\DH\\8109\\DH\\85-9320-01.pdf', 'C:\\WS\\WS\\Premium\\DH\\8109\\DH\\85-7626-01.pdf', 'C:\\WS\\WS\\Premium\\DH\\8109\\DH\\85-7612-01.pdf', 'C:\\WS\\WS\\Premium\\DH\\8109\\DH\\85-7210-01.pdf', 'C:\\WS\\WS\\Premium\\DH\\8109\\Prod-Mod\\85-9010-01.pdf', 'C:\\WS\\WS\\Premium\\DH\\8109\\Prod-Mod\\85-9001-01.pdf', 'C:\\WS\\WS\\Premium\\DH\\8120\\DH\\85-9220-01.pdf', 'C:\\WS\\WS\\Premium\\DS\\8306\\Corner Unit\\85-10624-01.pdf', 'C:\\WS\\WS\\Premium\\DS\\8307\\Premium DS - Window Std Unit_8307\\85-10692-01.pdf', 'C:\\WS\\WS\\Premium\\DS\\8307\\Premium DS - Window Std Unit_8307\\85-8046-01.pdf', 'C:\\WS\\WS\\Premium\\DS\\POCKET 8309\\Premium POCKET DS - Grilles_8309\\85-11915-01.pdf', 'C:\\WS\\WS\\Premium\\DS\\POCKET 8309\\Premium POCKET DS - Grilles_8309\\85-8588-01.pdf', 'C:\\WS\\WS\\Premium\\DS\\POCKET 8309\\Premium POCKET DS - Grilles_8309\\85-8598-01.pdf', 'C:\\WS\\WS\\Premium\\FRENCH CA\\8214\\French Casement\\45-03962.pdf', 'C:\\WS\\WS\\Premium\\FRENCH CA\\8214\\French Casement\\45-03935-01.pdf', 'C:\\WS\\WS\\Premium\\SGD\\Telescoping 8706\\2W\\08-2878-03.pdf', 'C:\\WS\\WS\\Premium\\SGD\\Telescoping 8706\\2W\\08-2876-03.pdf', 'C:\\WS\\WS\\Premium\\SGD\\Telescoping 8706\\2W\\08-2997-03.pdf', 'C:\\WS\\WS\\ProShield\\CA & AW\\7201\\AW\\85-1099-01.pdf', 'C:\\WS\\WS\\ProShield\\CA & AW\\7201\\AW\\85-1097-01.pdf', 'C:\\WS\\WS\\ProShield\\CA & AW\\7201\\CA\\08-3193-05.pdf', 'C:\\WS\\WS\\ProShield\\CA & AW\\7201\\Mull, Stack & Trim\\60-5893-01.pdf', 'C:\\WS\\WS\\ProShield\\DS\\7301\\Std Unit\\85-2118-01.pdf', 'C:\\WS\\WS\\ProShield\\DS\\733\\CA Pict, Tran, Sim Tran Std Unit\\511458A.pdf', 'C:\\WS\\WS\\ProShield\\Hung Window\\DH ProTilt_7101\\Double\\60-12634-01.pdf', 'C:\\WS\\WS\\ProShield\\Hung Window\\DH ProTilt_7101\\Double\\60-10723-01.pdf', 'C:\\WS\\WS\\Sequel\\CA & AW\\8207\\Bow, Bay & Garden\\70-3756-01.pdf', 'C:\\WS\\WS\\Sequel\\CA & AW\\8207\\Bow, Bay & Garden\\70-3757-01.pdf', 'C:\\WS\\WS\\Sequel\\CA & AW\\8207\\Bow, Bay & Garden\\70-3759-01.pdf', 'C:\\WS\\WS\\Sequel\\CA & AW\\8207\\Bow, Bay & Garden\\70-3761-01.pdf', 'C:\\WS\\WS\\Sequel\\CA & AW\\8207\\Bow, Bay & Garden\\70-3762-01.pdf', 'C:\\WS\\WS\\Sequel\\CA & AW\\8207\\Bow, Bay & Garden\\70-3764-01.pdf', 'C:\\WS\\WS\\Sequel\\CA & AW\\8207\\Bow, Bay & Garden\\70-3765-01.pdf', 'C:\\WS\\WS\\Sequel\\CA & AW\\8207\\Bow, Bay & Garden\\70-3766-01.pdf', 'C:\\WS\\WS\\Sequel\\CA & AW\\8207\\Bow, Bay & Garden\\70-3767-01.pdf', 'C:\\WS\\WS\\Sequel\\CA & AW\\8207\\Bow, Bay & Garden\\70-3751-01.pdf', 'C:\\WS\\WS\\Sequel\\CA & AW\\8207\\Bow, Bay & Garden\\70-3752-01.pdf', 'C:\\WS\\WS\\Sequel\\CA & AW\\8207\\Bow, Bay & Garden\\70-3753-01.pdf', 'C:\\WS\\WS\\Sequel\\CA & AW\\8207\\Bow, Bay & Garden\\70-3754-01.pdf', 'C:\\WS\\WS\\Sequel\\CA & AW\\8207\\Bow, Bay & Garden\\70-3755-01.pdf', 'C:\\WS\\WS\\Sequel\\CA & AW\\8207\\Bow, Bay & Garden\\08-1316-02.pdf', 'C:\\WS\\WS\\Signature\\CA & AW\\8205\\AW\\85-7575-01.pdf', 'C:\\WS\\WS\\Signature\\CA & AW\\8205\\AW\\85-7576-01.pdf', 'C:\\WS\\WS\\Signature\\Dbl-Hung\\8109\\DH_8109\\45-05060.pdf', 'C:\\WS\\WS\\Signature\\Dbl-Hung\\8109\\DH_8109\\85-8502-01.pdf', 'C:\\WS\\WS\\Signature\\Dbl-Hung\\8120\\DH\\85-12096-01.pdf', 'C:\\WS\\WS\\Signature\\Dbl-Hung\\8122\\DH\\45-13499.pdf', 'C:\\WS\\WS\\Signature\\Dbl-Hung\\8122\\DH\\45-11955.pdf', 'C:\\WS\\WS\\Signature\\Dbl-Hung\\8122\\DH\\45-11973.pdf', 'C:\\WS\\WS\\Signature\\Dbl-Hung\\8122\\DH\\45-13364.pdf', 'C:\\WS\\WS\\Signature\\DH Pic\\8123\\Pic\\45-13412.pdf', 'C:\\WS\\WS\\Signature\\DH Pic\\8123\\Pic\\45-14407.pdf', 'C:\\WS\\WS\\Signature\\DH Pic\\8123\\Pic\\45-14408.pdf', 'C:\\WS\\WS\\Signature\\DS\\Signature - DS_8306\\Signature DS - Grilles_8306\\85-11041-01.pdf', 'C:\\WS\\WS\\Signature\\DS\\Signature - DS_8306\\Signature DS - Grilles_8306\\85-8594-01.pdf', 'C:\\WS\\WS\\Signature\\DS\\Signature - DS_8306\\Signature DS - Grilles_8306\\85-11044-01.pdf', 'C:\\WS\\WS\\Signature\\DS\\Signature - DS_8306\\Signature DS - Grilles_8306\\85-8596-01.pdf', 'C:\\WS\\WS\\Signature\\DS\\Signature - DS_8306\\Signature DS - Mull, Stack & Trim_8306\\85-9937-01.pdf', 'C:\\WS\\WS\\Signature\\DS\\Signature - DS_8306\\Signature DS - Window Std Unit_8306\\85-9472-01.pdf', 'C:\\WS\\WS\\Visions 1000\\DS\\936\\Mull, Stack & Trim\\70-1575-01.pdf', 'C:\\WS\\WS\\Wood\\CA & AW\\6200\\Bow, Bay & Garden\\310243.pdf', 'C:\\WS\\WS\\Wood\\CA & AW\\6200\\French CA\\08-W2045.pdf', 'C:\\WS\\WS\\Wood\\CA & AW\\6200\\French CA\\08-W2044X.pdf', 'C:\\WS\\WS\\Wood\\CA & AW\\6200\\Mull, Stack & Trim\\09-0024B-W0186.pdf', 'C:\\WS\\WS\\Wood\\CA & AW\\6204\\AW\\70-1068-01.pdf', 'C:\\WS\\WS\\Wood\\CA & AW\\6204\\AW\\60-3075-01.pdf', 'C:\\WS\\WS\\Wood\\DS\\630\\Window Std Unit\\60-11335-01.pdf', 'C:\\WS\\WS\\Wood\\DS\\6301\\Mull, Stack & Trim\\09-0125-W0896.pdf', 'C:\\WS\\WS\\Wood\\DS\\6301\\Mull, Stack & Trim\\502728.pdf', 'C:\\WS\\WS\\Wood\\HGD\\1.75 In HGD IS_651\\EB, Segment\\08-1788-02.pdf', 'C:\\WS\\WS\\Wood\\HGD\\1.75 In HGD IS_6510\\1Wide\\45-09154.pdf', 'C:\\WS\\WS\\Wood\\Hung Window\\DH_610\\DH\\60-0757-01.pdf', 'C:\\WS\\WS\\Wood\\Hung Window\\DH_610\\DH\\60-12630-01.pdf', 'C:\\WS\\WS\\Wood\\Hung Window\\DH_610\\DH\\60-11717-01.pdf', 'C:\\WS\\WS\\Wood\\Hung Window\\DH_610\\Sash Set Pict, Tran, Fixed\\08-2185-02.pdf', 'C:\\WS\\WS\\Wood\\Hung Window\\DH_610\\Sash Set Pict, Tran, Fixed\\08-2478-02.pdf', 'C:\\WS\\WS\\Wood\\Hung Window\\DH_611\\Sash Replacement\\60-2456-01.pdf', 'C:\\WS\\WS\\Wood\\Hung Window\\DH_611\\Sash Replacement\\60-2457-01.pdf', 'C:\\WS\\WS\\Wood\\Hung Window\\DH_611\\Sash Replacement\\60-2454-01.pdf', 'C:\\WS\\WS\\Wood\\Hung Window\\DH_611\\Sash Replacement\\60-2460-01.pdf', 'C:\\WS\\WS\\Wood\\SGD\\Narrow Stile - 2009 - Omni Sill_6714\\Mull, Stack & Trim\\85-4951-01.pdf', 'C:\\WS\\WS\\Wood\\SGD\\Wide Stile - 2009 - Omni Sill_6715\\1Wide\\60-1096-02.pdf', 'C:\\WS\\WS\\Wood\\SGD\\Wide Stile - 2009 - Omni Sill_6715\\1Wide\\60-1094-01.pdf', 'C:\\WS\\WS\\Wood\\SGD\\Wide Stile - 2009 - Omni Sill_6715\\1Wide\\60-1092-01.pdf', 'C:\\WS\\WS\\Wood\\Slide Window\\Dbl-Triple Slide Window_6401\\Double\\60-8006-01.pdf', 'C:\\WS\\WS\\WS - EDS - IS\\6801\\Mull, Stack & Trim\\102773.pdf', 'C:\\WS\\WS\\WS - EDS - IS\\6801\\Mull, Stack & Trim\\103350.pdf', 'C:\\WS\\WS\\WS - EDS - IS\\6801\\Mull, Stack & Trim\\80-4123-01.pdf', 'C:\\WS\\WS\\WS - EDS - IS\\6801\\Mull, Stack & Trim\\80-4123-02.pdf', 'C:\\WS\\WS\\WS - EDS - IS\\6801\\Panel, Smooth FG\\80-2122-01.pdf', 'C:\\WS\\WS\\WS - EDS - IS\\6801\\Panel, Smooth FG\\80-1981-01.pdf', 'C:\\WS\\WS\\WS - EDS - IS\\6801\\Panel, Smooth FG\\80-1839-01.pdf', 'C:\\WS\\WS\\WS - EDS - IS\\6801\\Panel, Smooth Steel\\80-2762-01.pdf', 'C:\\WS\\WS\\WS - EDS - OS\\6901\\1W\\102829.pdf', 'C:\\WS\\WS\\WS - EDS - OS\\6901\\1W\\80-2087-01.pdf', 'C:\\WS\\WS\\WS - EDS - OS\\7901\\PNL\\80-1336-01.pdf', 'C:\\WS\\WS\\WS Alum Clad\\CA & AW\\8200\\EB, Segment\\08-2053-02.pdf', 'C:\\WS\\WS\\WS Alum Clad\\CA & AW\\8204\\Grilles\\70-1947-01.pdf', 'C:\\WS\\WS\\WS Alum Clad\\DH Window\\810\\DH\\85-4965-01.pdf', 'C:\\WS\\WS\\WS Alum Clad\\SGD\\Pocket Door  1.75 Panel 8712\\2L or 2R Single Direction\\85-3313-01.pdf', 'C:\\WS\\WS\\WS Alum Clad\\SGD\\Pocket Door  1.75 Panel 8712\\2L or 2R Single Direction\\85-2440-01.pdf', 'C:\\WS\\WS\\WS Alum Clad\\SGD\\Pocket Door  1.75 Panel 8712\\2L2R 4W Biparting\\85-3331-04.pdf', 'C:\\WS\\WS\\WS Alum Clad\\SGD\\Pocket Door 2.25 Panel 8713\\2L or 2R Single Direction\\85-3779-03.pdf', 'C:\\WS\\WS\\WS HR175\\SH_6101\\Single\\60-12643-01.pdf', 'C:\\WS\\WS\\WS HR175\\SH_6101\\Single\\60-12638-01.pdf', 'C:\\WS\\WS\\WS HR175\\SH_6101\\Single\\60-12602-01.pdf', 'C:\\WS\\WS\\WS HR175\\SH_6101\\Single\\60-12601-01.pdf', 'C:\\WS\\WS\\WS HR175\\SH_6101\\Single\\60-12644-01.pdf', 'C:\\WS\\WS\\WS HR175\\SH_6101\\Single\\60-12636-01.pdf']
Existent files: ['C:\\WS\\WS\\Aspire\\CA & AW\\7205\\AW\\85-7534-01.pdf']
Grouped files: [['C:\\WS\\WS\\Aspire\\CA & AW\\7205\\AW\\85-7534-01.pdf']]

2 个答案:

答案 0 :(得分:1)

您确实应该可以使这个问题更短。为什么不写一些功能呢?然后,您可以确定某个功能是问题所在,而您的问题将仅与该功能有关。

也许这会有所帮助?

def get_filenames_list(csv_filename):
    import os
    import pandas
    # Read table from CSV file
    table = pandas.read_csv(csv_filename)
    # Create list of all files from table
    filenames = []
    for name, path in zip(table["Name"], table["Found In"]):
        filename = "{}.pdf".format(os.path.join(path, name))
        filenames.append(filename)
    return filenames

def remove_nonexistent_files(filenames):
    import os
    # Remove nonexistent files from list of filenames
    filenames = list(filter(os.path.isfile, filenames))
    return filenames

def group_identical_files(filenames, buffer_size=1024):
    # Remove duplicates from list of filenames
    filenames = list(set(filenames))
    groups = []
    while len(filenames) > 0:
        a_filename = filenames.pop()
        group = [a_filename]
        for b_filename in filenames:
            with open(a_filename, "rb") as a_handle:
                with open(b_filename, "rb") as b_handle:
                    identical = False
                    while True:
                        a_buffer = a_handle.read(buffer_size)
                        b_buffer = b_handle.read(buffer_size)
                        if a_buffer != b_buffer:
                            break
                        if len(a_buffer) == 0 and len(b_buffer) == 0:
                            # EOF is reached for both files
                            identical = True
                            break
            if identical:
                group.append(b_filename)
                filenames.remove(b_filename)
        groups.append(group)
    return groups

if __name__ == "__main__":
    files = get_filenames_list("C://Users//27659//Desktop//Unique Wood Profiles.csv")
    print("All files:", files)
    existent_files = remove_nonexistent_files(files)
    print("Existent files:", existent_files)
    grouped_files = group_identical_files(existent_files)
    print("Grouped files:", grouped_files)

您可能需要调整CSV文件的路径(我从上面的代码中获取了该路径),否则,您可以运行该脚本,它将向您显示

  • All files:包含从CSV文件获取的所有文件名。
  • Existent files:因此,您可以检查脚本是否成功将文件名放在一起。 (如果此列表为空,您将知道这些文件不存在,或者上一步不起作用。)
  • Grouped files:每个列表包含相同文件名的结果。如果列表仅包含一个元素,则没有其他文件与此元素相同。

答案 1 :(得分:0)

我将其分解为最简单的版本,以解决基本问题。这就是为什么一个路径在我的路径列表中起作用而其他所有路径都不起作用的原因呢?我纯粹是靠运气发现的是,当我进入路径位置并从我的pdm库中打开文件时,python的os模块随后会将其识别为路径。对我来说真的很奇怪。如果有人能解释为什么会这样,我将不胜感激。

我与我们的IT部门进行了交谈,他们说使用C:路径而不是服务器路径可能与我有关。他们不确定。他们对pdm的结构不太了解。

'

这是我编写的用于创建简单的禁止进入清单的代码。

'

import pandas as pd
import os

#creates a dataframe in python of the information in my csv file

main_df = pd.read_csv("C://Users//27659//Desktop//Unique Wood Profiles.csv")

# Turns the columns of the dataframe into lists

drawing_number_list = main_df['Name'].tolist()
description_list = main_df['Description'].tolist()
found_in_list = main_df['Found In'].tolist()

# I've always done my empty lists this way.  i never took the time to learn about empty lists and this only adds one more line of code.

full_file_list = ['placeholder']

# fill the list with the concatenated strings from the other list.  puts together the full path to the file.

for i in range(0, len(drawing_number_list)):
    full_file_list.append(found_in_list[i] + drawing_number_list[i] + '.pdf')

# index 0 of the list is still the string 'placeholder' this deletes it.

del full_file_list[0]

# some boolean logic that will tell me if the path is something the computer can use.  this also puts the print out in a nice format that can be copy and pasted from the print window.

for i in range(0, len(full_file_list)):
    if os.path.exists(full_file_list[i]):
        print('1\t' + full_file_list[i])
    else:
        print('0\t' + full_file_list[i])

'

它与Jayjayyy的代码非常相似。通过这种方式进行打印,我可以将打印内容复制并粘贴到txt文件中,并仔细检查每个文件,然后打开和关闭路径所指向的文件。由于列表中没有那么多文件,因此我将手动进行操作。如果我有更多,则必须从实际服务器获取路径。这个项目对我来说是一个一次性的检查,因此拥有服务器路径并不是那么重要。我建议如果将来有人遇到相同的问题,请花些时间直接从服务器及其附带的权限中获取正确的路径。它将为您节省很多头痛。