---
# System prepended metadata

title: src_cs_db_01

---

# src_cs_db_01

```
import json
import requests
from requests.structures import CaseInsensitiveDict
from requests.exceptions import Timeout
import csv
from os import listdir
from os.path import isfile, isdir, join
from datetime import datetime
'''


'''
def main():
    # 指定要列出所有檔案的目錄 
    path = "D:\\VROPS\\MSSQL_DB_Server_Capacity_Report\\"
    # 取得所有檔案與子目錄名稱 2022-12-27 134629_000623 MSSQL DB Server Capacity Report ProductionDB.csv
    files = listdir(path)
    lastfilename = files[-1]
    #print(lastfilepath)
    try:
            src_stime = lastfilename.split('_', 1 )[0]
            # 產生檔案的絕對路徑
            fullpath = join(path, lastfilename)
            # 判斷 fullpath 是檔案還是目錄
            if isfile(fullpath):
                #print(f)
                with open(fullpath,encoding='utf-8') as file:
                    csvreader = csv.reader(file)  
                    headers = next(csvreader)
                    for row in csvreader:
                        if len(row)>0:
                            row = ','.join(map(str,row))
                            print(f"{src_stime},{row}")
    except Exception as a:
        print(',')
        
    
if __name__ == '__main__':
    main()
   

    
```















    