Const ForReading 1, ForWriting 2, ForAppending = 8 Dim f_csv, fs_csv Dim fs_csv1, fs_csv2, fs_csv3, fs_csv4, fs_csv5, fs_csv6, fs_csv7, fs_csv8, fs_csv_all Dim f_csv1, f_csv2, f_csv3, f_csv4, f_csv5, f_csv6, f_csv7, f_csv8, f_csv_all Dim Day_csv, Month_csv, Year_csv, nom_rec, nb_char_nom_rec, numero_ligne_csv Dim path_search_csv, found_csv, found_csv_path, ligne_csv, nom_voie_ligne, array_cellule_csv, date_de_recherche, file_in_folder Dim no_rec_voie, capteur_actif, capteur_nom, date_time_array, date_ligne, heure_ligne, date_time_ligne, ligne_a_copier, no_voie_csv Dim fso, folder, fld 'Message : Service occupé, veuillez patientez SVP... Call ShowSystemAlarm ("Service occupé, veuillez patientez SVP...!") nom_rec = SmartTags("DB_Rapport_Data_Enregistrement.Nom") nb_char_nom_rec = Len(nom_rec) date_de_recherche = SmartTags("Debut_Rec_Day") & "/" & SmartTags("Debut_Rec_Month") & "/" & SmartTags("Debut_Rec_Year") & " " & "00:00:00" found_csv = "" 'init file_in_folder = False 'init 'Création des objets file pour la gestion des fichiers csv pour chaque capteur et ouverture des ficheirs csv Set fs_csv_all = CreateObject("Scripting.FileSystemObject") On Error Resume Next Set f_csv_all = fs_csv_all.OpenTextFile((Path_CSVs & "CSV_All.csv"), ForAppending, True) Set fs_csv1 = CreateObject("Scripting.FileSystemObject") On Error Resume Next Set f_csv1 = fs_csv1.OpenTextFile((Path_CSVs & "CSV1.csv"), ForAppending, True) Set fs_csv2 = CreateObject("Scripting.FileSystemObject") On Error Resume Next Set f_csv2 = fs_csv2.OpenTextFile((Path_CSVs & "CSV2.csv"), ForAppending, True) Set fs_csv3 = CreateObject("Scripting.FileSystemObject") On Error Resume Next Set f_csv3 = fs_csv3.OpenTextFile((Path_CSVs & "CSV3.csv"), ForAppending, True) Set fs_csv4 = CreateObject("Scripting.FileSystemObject") On Error Resume Next Set f_csv4 = fs_csv4.OpenTextFile((Path_CSVs & "CSV4.csv"), ForAppending, True) Set fs_csv5 = CreateObject("Scripting.FileSystemObject") On Error Resume Next Set f_csv5 = fs_csv5.OpenTextFile((Path_CSVs & "CSV5.csv"), ForAppending, True) Set fs_csv6 = CreateObject("Scripting.FileSystemObject") On Error Resume Next Set f_csv6 = fs_csv6.OpenTextFile((Path_CSVs & "CSV6.csv"), ForAppending, True) Set fs_csv7 = CreateObject("Scripting.FileSystemObject") On Error Resume Next Set f_csv7 = fs_csv7.OpenTextFile((Path_CSVs & "CSV7.csv"), ForAppending, True) Set fs_csv8 = CreateObject("Scripting.FileSystemObject") On Error Resume Next Set f_csv8 = fs_csv8.OpenTextFile((Path_CSVs & "CSV8.csv"), ForAppending, True) 'Recherche des fichiers concernés par l'enregistrement Do 'Message : Service occupé, veuillez patientez SVP... Call ShowSystemAlarm ("Service occupé, veuillez patientez SVP...!") Day_csv=Day(date_de_recherche) Month_csv=Month(date_de_recherche) Year_csv=Year(date_de_recherche) 'Chemin approximatif fichier CSV à rechercher path_search_csv = Storage_Path & "Annee_" & Year_csv & "\Mois_" & Month_csv & "\Jour_" & Day_csv & "" Set fso = CreateObject("Scripting.FileSystemObject") If fso.FolderExists(path_search_csv) Then For Each fld In fso.GetFolder(path_search_csv).Files If Left(fld.Name, nb_char_nom_rec) nom_rec And Right(fld.Name, 4) ".csv" Then 'Message : Service occupé, veuillez patientez SVP... Call ShowSystemAlarm ("Service occupé, veuillez patientez SVP...!") found_csv = fld.Name file_in_folder = True 'Création d'un objet file system pour la recherche des 'fichiers csv comprenant les valeurs d'archivages Set fs_csv = CreateObject("Scripting.FileSystemObject") On Error Resume Next 'Ouverture du fichier csv trouvé found_csv_path= Storage_Path & "Annee_" & Year_csv & "\Mois_" & Month_csv & "\Jour_" & Day_csv & "" & found_csv Set f_csv = fs_csv.OpenTextFile(found_csv_path, ForReading, True) If Err.Number=0 Then 'Lire chaque ligne jusqu'à la dernière ligne du fichier numero_ligne_csv = 1 'init Do While f_csv.AtEndOfStream = False ligne_csv = f_csv.ReadLine 'lecture de ligne du fichier csv array_cellule_csv = Split(ligne_csv, ";")'séparation dés données comprise sur la ligne : chaque cellule -> array date_time_ligne = Replace(array_cellule_csv(1),Chr(34),"")'suppression des guillemets générés par le split autour de la date et heure nom_voie_ligne = Replace(array_cellule_csv(0),Chr(34),"")'suppression des guillemets générés par le split date_time_array = Split(date_time_ligne, " ")'séparation de la date et de l'heure date_ligne = date_time_array(0) heure_ligne = date_time_array(1) 'Capteur concerné par la lecture de la ligne capteur_actif = False no_rec_voie = 0 no_voie_csv = Right(nom_voie_ligne,17) If no_voie_csv = "_record[1].Valeur" Then no_rec_voie = 1 capteur_actif = SmartTags("DB_Rapport_Data_Enregistrement.Actif_capteur[1]") capteur_nom = SmartTags("DB_Rapport_Data_Enregistrement.Nom_capteur[1]") End If If no_voie_csv = "_record[2].Valeur" Then no_rec_voie = 2 capteur_actif = SmartTags("DB_Rapport_Data_Enregistrement.Actif_capteur[2]") capteur_nom = SmartTags("DB_Rapport_Data_Enregistrement.Nom_capteur[2]") End If If no_voie_csv = "_record[3].Valeur" Then no_rec_voie = 3 capteur_actif = SmartTags("DB_Rapport_Data_Enregistrement.Actif_capteur[3]") capteur_nom = SmartTags("DB_Rapport_Data_Enregistrement.Nom_capteur[3]") End If If no_voie_csv = "_record[4].Valeur" Then no_rec_voie = 4 capteur_actif = SmartTags("DB_Rapport_Data_Enregistrement.Actif_capteur[4]") capteur_nom = SmartTags("DB_Rapport_Data_Enregistrement.Nom_capteur[4]") End If If no_voie_csv = "_record[5].Valeur" Then no_rec_voie = 5 capteur_actif = SmartTags("DB_Rapport_Data_Enregistrement.Actif_capteur[5]") capteur_nom = SmartTags("DB_Rapport_Data_Enregistrement.Nom_capteur[5]") End If If no_voie_csv = "_record[6].Valeur" Then no_rec_voie = 6 capteur_actif = SmartTags("DB_Rapport_Data_Enregistrement.Actif_capteur[6]") capteur_nom = SmartTags("DB_Rapport_Data_Enregistrement.Nom_capteur[6]") End If If no_voie_csv = "_record[7].Valeur" Then no_rec_voie = 7 capteur_actif = SmartTags("DB_Rapport_Data_Enregistrement.Actif_capteur[7]") capteur_nom = SmartTags("DB_Rapport_Data_Enregistrement.Nom_capteur[7]") End If If no_voie_csv = "_record[8].Valeur" Then no_rec_voie = 8 capteur_actif = SmartTags("DB_Rapport_Data_Enregistrement.Actif_capteur[8]") capteur_nom = SmartTags("DB_Rapport_Data_Enregistrement.Nom_capteur[8]") End If If no_voie_csv = "_record[9].Valeur" Then no_rec_voie = 9 capteur_actif = SmartTags("DB_Rapport_Data_Enregistrement.Actif_capteur[9]") capteur_nom = SmartTags("DB_Rapport_Data_Enregistrement.Nom_capteur[9]") End If If no_voie_csv = "record[10].Valeur" Then no_rec_voie = 10 capteur_actif = SmartTags("DB_Rapport_Data_Enregistrement.Actif_capteur[10]") capteur_nom = SmartTags("DB_Rapport_Data_Enregistrement.Nom_capteur[10]") End If 'Recopie de la ligne du fichier CSV dans le Fichier CSV du capteur en cours If capteur_actif Then ligne_a_copier = capteur_nom & ";" & array_cellule_csv(2) & ";" & heure_ligne & ";" & date_ligne & ";" & date_time_ligne Select Case no_rec_voie Case 1 f_csv1.WriteLine ligne_a_copier Case 2 f_csv2.WriteLine ligne_a_copier Case 3 f_csv3.WriteLine ligne_a_copier Case 4 f_csv4.WriteLine ligne_a_copier Case 5 f_csv5.WriteLine ligne_a_copier Case 6 f_csv6.WriteLine ligne_a_copier Case 7 f_csv7.WriteLine ligne_a_copier Case 8 f_csv8.WriteLine ligne_a_copier Case 9 f_csv8.WriteLine ligne_a_copier Case 10 f_csv8.WriteLine ligne_a_copier End Select End If 'Recopie de la ligne du fichier CSV général '(pour affichage de la courbe à partir de ce fichier) If no_rec_voie <> 0 Or numero_ligne_csv = 1 Then f_csv_all.WriteLine ligne_csv numero_ligne_csv = numero_ligne_csv + 1 End If Loop End If 'Fermeture du fichier f_csv.Close 'Libération des objets Set f_csv = Nothing Set fs_csv = Nothing End If Next 'on passe au jour suivant (dossier Jour_XX suivant) date_de_recherche = DateAdd("d",1,date_de_recherche) Else file_in_folder = False End If Set folder = Nothing Set fso = Nothing Loop While (file_in_folder) 'Fermeture des fichiers csv pour chaque capteur f_csv_all.Close f_csv1.Close f_csv2.Close f_csv3.Close f_csv4.Close f_csv5.Close f_csv6.Close f_csv7.Close f_csv8.Close 'Libération des objets Set f_csv_all = Nothing Set f_csv1 = Nothing Set f_csv2 = Nothing Set f_csv3 = Nothing Set f_csv4 = Nothing Set f_csv5 = Nothing Set f_csv6 = Nothing Set f_csv7 = Nothing Set f_csv8 = Nothing Set fs_csv_all = Nothing Set fs_csv = Nothing Set fs_csv1 = Nothing Set fs_csv2 = Nothing Set fs_csv3 = Nothing Set fs_csv4 = Nothing Set fs_csv5 = Nothing Set fs_csv6 = Nothing Set fs_csv7 = Nothing Set fs_csv8 = Nothing
J'ai un code qui marche l'OS Windows CE. Mais c'est plus simple avec Windows CE car on peut utiliser "Dir" qui accepte les caractères joker (*) et (?).
Forum > Visual Basic 6
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionOption Explicit Const cstPathRoot = "H:\SCRIPTS" Const cstNameFile = "rec01" Const cstExtensionFile = "csv" Call CheckFiles(Day(Date-1), Month(Date-1), Year(Date-1)) Call CheckFiles(Day(Date), Month(Date), Year(Date)) Sub CheckFiles(argDay, argMonth, argYear) Dim objFso, strPath, strFile Set objFso = CreateObject("Scripting.FileSystemObject") strPath = cstPathRoot & "Annee_" & argYear & Chr(92) &_ "Mois_" & argMonth & Chr(92) & "Jour_" & argDay If objFso.FolderExists(strPath) = True Then For Each strFile in objFso.GetFolder(strPath).Files If Left(strFile.Name, Len(cstNameFile)) = cstNameFile And _ LCase(objFso.GetExtensionName(strFile.Name)) = cstExtensionFile Then MsgBox strFile.Name,,strPath End If Next End if Set objFso = Nothing End Sub