'how to find files on directory based on filename pattern in python script
I have to modify my script to find the file that has a based on filename pattern, as of now it only export what specific filename that assigned on the script, can someone help me what I need to add or modify to my script?
Scenario: I have file has date on its filename
MyProject_PO_20220516.csv
I still need to edit my script manually to exact filename everytime I want to import the csv file
Solution that I need to modify to my script
modify the script that can find the file with initial filename
Ex.
MyProject_PO + "_" + date + .csv
the initial filename is MyProject_PO_ , the script will find the file that met the pattern of filename on the script regardless what DATE that saved on it.
My Script
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from googleapiclient.discovery import build
import csv
SPREADSHEET_ID = 'SAMPLE_GSHEETDRIVE'
worksheet_name = 'CSVimport'
my_csv = 'MyProject_PO_20220516.csv'
credentials = 'key123.json'
def export_csv(my_csv, sheet_id):
with open(my_csv, 'r', encoding = "ISO-8859-1") as csv_file:
csvContents = csv_file.read()
body = {
'requests': [{
'pasteData': {
"coordinate": {
"sheetId": sheet_id,
"rowIndex": "0",
"columnIndex": "0",
},
"data": csvContents,
"type": 'PASTE_NORMAL',
"delimiter": ',',
}
}]
}
If you need more details let me know. Thank you in advance!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
