mirror of
https://github.com/komiko44240BB/BattleBay_tool_v1.0.git
synced 2026-01-18 16:27:29 +01:00
maj data
This commit is contained in:
28
scriptspy/from nothing to csv.py
Normal file
28
scriptspy/from nothing to csv.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import os
|
||||
import tkinter as tk
|
||||
from tkinter import filedialog
|
||||
|
||||
def choisir_dossier():
|
||||
root = tk.Tk()
|
||||
root.withdraw() # Cache la fenêtre principale de Tkinter
|
||||
dossier = filedialog.askdirectory(title="Choisissez un dossier")
|
||||
return dossier
|
||||
|
||||
def changer_extension_en_csv(dossier):
|
||||
if not os.path.exists(dossier):
|
||||
print(f"Le dossier {dossier} n'existe pas.")
|
||||
return
|
||||
|
||||
for filename in os.listdir(dossier):
|
||||
chemin_complet = os.path.join(dossier, filename)
|
||||
if os.path.isfile(chemin_complet):
|
||||
nouveau_nom = os.path.splitext(chemin_complet)[0] + ".csv"
|
||||
os.rename(chemin_complet, nouveau_nom)
|
||||
print(f"Renommé: {chemin_complet} -> {nouveau_nom}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
dossier_choisi = choisir_dossier()
|
||||
if dossier_choisi:
|
||||
changer_extension_en_csv(dossier_choisi)
|
||||
else:
|
||||
print("Aucun dossier sélectionné.")
|
||||
@@ -5,7 +5,7 @@ from tkinter.filedialog import askdirectory
|
||||
def replace_commas_in_txt_files(directory):
|
||||
# Parcours des fichiers dans le répertoire
|
||||
for filename in os.listdir(directory):
|
||||
if filename.endswith(".txt"):
|
||||
if filename.endswith(".csv"):
|
||||
file_path = os.path.join(directory, filename)
|
||||
|
||||
# Lecture du contenu du fichier
|
||||
@@ -15,20 +15,11 @@ def replace_commas_in_txt_files(directory):
|
||||
# Remplacement des virgules par des points-virgules
|
||||
new_content = content.replace(";", ",")
|
||||
|
||||
# Écriture du nouveau contenu dans le fichier .txt
|
||||
# Écriture du nouveau contenu dans le même fichier
|
||||
with open(file_path, 'w', encoding='utf-8') as file:
|
||||
file.write(new_content)
|
||||
|
||||
print(f"Fichier modifié : {filename}")
|
||||
|
||||
# Création d'un fichier CSV avec le même contenu
|
||||
csv_filename = filename.replace(".txt", ".csv")
|
||||
csv_path = os.path.join(directory, csv_filename)
|
||||
|
||||
with open(csv_path, 'w', encoding='utf-8') as csv_file:
|
||||
csv_file.write(new_content)
|
||||
|
||||
print(f"Fichier CSV créé : {csv_filename}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Création d'une fenêtre Tkinter pour la sélection du dossier
|
||||
@@ -37,6 +28,6 @@ if __name__ == "__main__":
|
||||
|
||||
if folder_selected:
|
||||
replace_commas_in_txt_files(folder_selected)
|
||||
print("Tous les fichiers ont été traités et des fichiers CSV ont été créés.")
|
||||
print("Tous les fichiers ont été traités.")
|
||||
else:
|
||||
print("Aucun dossier sélectionné.")
|
||||
|
||||
Reference in New Issue
Block a user