편집 기록

편집 기록
  • 프로필 nowp님의 편집
    날짜2021.05.24

    [python] json 저장


    def lnktojson(lnkdata_path):
    
        file_list = glob.glob(os.path.join(lnkdata_path, '*.lnk'))
    
        json_data = []
    
        for f_idx in range(len(file_list)):
            try:
                #json 데이터 저장
                file = Lnk.file_open(file_list[f_idx])
                file.show_all_info()
                json_data.append(file.get_all_info())
    
                print("저장 완료\n\n")
    
            except:
                    print("\n")
    
        with open('lnk.json', 'w') as json_file:
            json.dump(json_data, json_file, indent=4)
    
    
    
    #main
    if __name__=="__main__":
        print("분석할 파일이 위치한 경로를 입력하십시오.\n")
        lnkdata_path=input("경로 : ")
    
        lnktojson(lnkdata_path)
    

    이렇게 저장을 하면

    [
        [
            {
                "File Attributes0": "FILE_ATTRIBUTE_ARCHIVE",
                "Target File Creation TimeZone": "UTC",
                "Target File Creation Time": "2020-12-03 00:25:00",
                "Target File Access TimeZone": "UTC",
                "Target File Access Time": "2020-12-06 09:36:33",
                "Target File Write TimeZone": "UTC",
                .
                .
                .
                "Target File Size": "123542720bytes",
                "IconIndex": "0",
                "Show Command": "SW_SHOWNORMAL",
                "Drivetype": "DRIVE_FIXED",
                "Driveserialnumber": "ef31ee58",
                "Volumelable": "",
                "Localbasepath Unicode": "None",
                "Localbasepath": "C:\\Users\\User\\AppData\\Local\\Programs\\Evernote\\Evernote.exe",
                .
                .
                .
            }
        ],
        [
            {
                "File Attributes0": "FILE_ATTRIBUTE_ARCHIVE",
                "Target File Creation TimeZone": "UTC",
                "Target File Creation Time": "2021-03-25 09:30:36",
                "Target File Access TimeZone": "UTC",
                "Target File Access Time": "2021-03-25 09:30:37",
                "Target File Write TimeZone": "UTC",
                .
                .
                .
                "Target File Size": "126577744bytes",
                "IconIndex": "0",
                "Show Command": "SW_SHOWNORMAL",
                "Drivetype": "DRIVE_FIXED",
                "Driveserialnumber": "ef31ee58",
                "Volumelable": "",
                "Localbasepath Unicode": "None",
                "Localbasepath": "C:\\Users\\User\\AppData\\Local\\Programs\\Notion\\Notion.exe",
                .
                .
                .
            }
        ]
    ]
    

    이런 식으로 대괄호 안에 대괄호 안에 중괄호로 저장됩니다. 보통은

    {
        {
            #데이터
        },
        {
            #데이터
        }
    }
    
    

    이렇게 저장되지 않나요? 어떻게 해야 저런 식으로 저장되는지 알고 싶습니다.

    json 안에 들어가는 정보는

            info_list = []
            info = dict()
            file_attribute = self.__file_attribute()
    
            #info_list에 들어갈 내용들
    
            info_list.append(info)
    
    

    이렇게 만들어집니다.

    며칠을 고민해 봐도 답이 나오지 않습니다. 도와주세요.

  • 프로필 mindy0323님의 편집
    날짜2021.05.24

    [python] json 저장


    def lnktojson(lnkdata_path):
    
        file_list = glob.glob(os.path.join(lnkdata_path, '*.lnk'))
    
        json_data = []
    
        for f_idx in range(len(file_list)):
            try:
                #json 데이터 저장
                file = Lnk.file_open(file_list[f_idx])
                file.show_all_info()
                json_data.append(file.get_all_info())
    
                print("저장 완료\n\n")
    
            except:
                    print("\n")
    
        with open('lnk.json', 'w') as json_file:
            json.dump(json_data, json_file, indent=4)
    
    
    
    #main
    if __name__=="__main__":
        print("분석할 파일이 위치한 경로를 입력하십시오.\n")
        lnkdata_path=input("경로 : ")
    
        lnktojson(lnkdata_path)
    

    이렇게 저장을 하면

    [
        [
            {
                "File Attributes0": "FILE_ATTRIBUTE_ARCHIVE",
                "Target File Creation TimeZone": "UTC",
                "Target File Creation Time": "2020-12-03 00:25:00",
                "Target File Access TimeZone": "UTC",
                "Target File Access Time": "2020-12-06 09:36:33",
                "Target File Write TimeZone": "UTC",
                .
                .
                .
                "Target File Size": "123542720bytes",
                "IconIndex": "0",
                "Show Command": "SW_SHOWNORMAL",
                "Drivetype": "DRIVE_FIXED",
                "Driveserialnumber": "ef31ee58",
                "Volumelable": "",
                "Localbasepath Unicode": "None",
                "Localbasepath": "C:\\Users\\User\\AppData\\Local\\Programs\\Evernote\\Evernote.exe",
                .
                .
                .
            }
        ],
        [
            {
                "File Attributes0": "FILE_ATTRIBUTE_ARCHIVE",
                "Target File Creation TimeZone": "UTC",
                "Target File Creation Time": "2021-03-25 09:30:36",
                "Target File Access TimeZone": "UTC",
                "Target File Access Time": "2021-03-25 09:30:37",
                "Target File Write TimeZone": "UTC",
                .
                .
                .
                "Target File Size": "126577744bytes",
                "IconIndex": "0",
                "Show Command": "SW_SHOWNORMAL",
                "Drivetype": "DRIVE_FIXED",
                "Driveserialnumber": "ef31ee58",
                "Volumelable": "",
                "Localbasepath Unicode": "None",
                "Localbasepath": "C:\\Users\\User\\AppData\\Local\\Programs\\Notion\\Notion.exe",
                .
                .
                .
            }
        ]
    ]
    

    이런 식으로 대괄호 안에 대괄호 안에 중괄호로 저장됩니다. 보통은

    {
        {
            #데이터
        },
        {
            #데이터
        }
    }
    
    

    이렇게 저장되지 않나요? 어떻게 해야 저런 식으로 저장되는지 알고 싶습니다ㅜㅜ

    json 안에 들어가는 정보는

            info_list = []
            info = dict()
            file_attribute = self.__file_attribute()
    
            #info_list에 들어갈 내용들
    
            info_list.append(info)
    
    

    이렇게 만들어집니다.

    ㅠㅠ 며칠을 고민해 봐도 답이 나오지 않습니다... 도와주세요...