Céation/lecture répertoire en vba

Résolu
cs_ordino Messages postés 20 Date d'inscription mercredi 18 août 2004 Statut Membre Dernière intervention 13 novembre 2012 - 26 oct. 2005 à 18:27
cs_ordino Messages postés 20 Date d'inscription mercredi 18 août 2004 Statut Membre Dernière intervention 13 novembre 2012 - 28 oct. 2005 à 21:16
Bonjour!
Je travaille sur access 2000
Je veux
1) Ajouter, par exemple, le répertoire "ClientDuMoisOctobre" dans le répertoire "c:\ClientsDe2005"

2)Plus tard afficher à l'écran les fichiers de "c:\ClientsDe2005\ClientDuMoisOctobre"

3) à partir de cette liste ouvrir un fichier sélectionné

Toute aide sera grandement appréciée
ORDINOORDINO

6 réponses

cs_ordino Messages postés 20 Date d'inscription mercredi 18 août 2004 Statut Membre Dernière intervention 13 novembre 2012
28 oct. 2005 à 21:16
Encore une fois un grand merci.
J'ai appris les fonctions et méthodes suivantes:

CreateObject("WScript.Shell")
.run
CreateObject("Scripting.FileSystemObject")
GetFolder()
FolderExists ()
CreateFolder()
.SubFolders
.Files
DatePart
Array()

Ils fonctionnent en VBA mais ils sont inconnus dans l'aide.
Où puis-je avoir plus de renseignements?
Cela m?aiderait à solutionner la 3ième partie de mon problème :
Ouvrir un fichier dont j'ai le path (word, excel, courriel, .pdf etc)

Le code suivant fonctionne très bien dans un module Access 2000!

Sub CréerRépertoire()
' conversion du 1er caractère du mois actuel en majuscule
Dim m1, m2, mm, path1, path2
Dim fso, f, f1, fichier, Subfichier, Resultat

m1 = DatePart("m", Date)
m2 = Array("", "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre")
mm = m2(m1)
'MsgBox mm

' vérification des répertoires
path1 = "d:\ClientsDe" & Year(Date) & ""
path2 = path1 & "ClientDuMois" & mm & ""
MsgBox path1 & vbCrLf & path2

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(path1)

If Not fso.FolderExists(path2) Then
Set f = fso.CreateFolder(path2)
Else
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'lecture des répertoires contenus dans path1
Set f = fso.GetFolder(path1)
For Each Subfichier In f.SubFolders
MsgBox "vérification du nom du répertoire traité: " & Subfichier
'lecture des fichiers contenus dans les sous-répertoires de path1
Set f1 = Subfichier.Files
For Each fichier In f1
Resultat = Resultat & vbCrLf & vbCrLf & fichier
Next
Next
MsgBox Resultat
Set fso = Nothing
'Les 4 lignes suivantes ne fonctionnent pas avec ma version d'access 2000
' mais pas nécessaires pour la solution de mon problême
'Dim wshShell
'Set wshShell = wscript.CreateObject("WScript.Shell")
'Verif = wshShell.PopUp(Resultat & vbCrLf & vbCrLf, 20, "Le répertoire " & path1 & " contient les sous-répertoires et fichiers suivants: ")
'wscript.Quit

End Sub
3
jpleroisse Messages postés 1788 Date d'inscription mardi 7 novembre 2000 Statut Membre Dernière intervention 11 mars 2006 27
26 oct. 2005 à 19:42
Bonsoir,

Où se trouve ClientDuMoisOctobre(il faut le créer ou il existe) et que contient-il ??



jpleroisse
0
cs_ordino Messages postés 20 Date d'inscription mercredi 18 août 2004 Statut Membre Dernière intervention 13 novembre 2012
26 oct. 2005 à 20:13
IL FAUT LE CRÉER VIDE.
D'AUTRES USAGER VONT Y AJOUTER DES FICHIERS (WORD ,EXCELL...)

JE VEUX LES FICHIERS (LISTE) POUR POUVOIR LES OUVRIR (SHELL ???)

ORDINOORDINO
0
cs_jeanmarc Messages postés 34 Date d'inscription mardi 18 juin 2002 Statut Membre Dernière intervention 22 novembre 2005
27 oct. 2005 à 01:14
Bonsoir,
J'ai avancé pour "ton" script.
J'ai ajouté des tests évidents.
C'est écrit en VBS, mais on peux l'insérer dans du VBA.

'1) Ajouter, par exemple, le répertoire "ClientDuMoisOctobre" dans le répertoire "c:\ClientsDe2005"
'2)Plus tard afficher à l'écran les fichiers de "c:\ClientsDe2005\ClientDuMoisOctobre"


' Test si path "ClientDuMoismm" existe'
'
' conversion du 1er caractère du mois actuel en majuscule
Dim m1, m2, mm, path1, path2, dossier, fichiers, fso, f1, fso1, f2, fichier
m1 = DatePart("m", Date)
m2 = Array("","janvier","février","mars","avril","mai","juin","juillet","août","septembre","octobre","novembre","décembre")
mm = m2(m1)
mois = Ucase(Left(mm, 1)) & Mid(mm, 2)
'msgbox "mois windows: " & mm &vbCrLf&"mois modifié : " & mois


' vérification des répertoires
path1 = "d:\ClientsDe" & Year(Date) & ""
path2 = "d:\ClientDuMois" & mois & ""
'msgbox Path1 &vbCrLf& path2


Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(path1)


If Not fso.FolderExists(path2) Then
Set f = fso.CreateFolder(path2)
' msgBox "Création du répertoire " & path2 & " effectuée" &vbCrLf&vbCrLf& "Copie des fichiers du répertoire " & path1 &vbCrLf& "vers " & path2 & " effectuée",vbInformation
Else
' msgBox "Copie des fichiers du répertoire " & path1 &vbCrLf& "vers " & path2 & " effectuée",vbInformation
End if


For Each fichier in f.Files
' msgbox fichier & " test2"
fso.CopyFile fichier, path2
msgBox "Copie du fichier " & f.Name & " du répertoire " & path1 &vbCrLf& "vers " & path2 & " effectuée",vbInformation
Next
Set fso = Nothing


Dim wshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "C:\WINDOWS\EXPLORER.EXE /n,/e," & path2
wscript.Quit
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_ordino Messages postés 20 Date d'inscription mercredi 18 août 2004 Statut Membre Dernière intervention 13 novembre 2012
27 oct. 2005 à 03:56
Merci beaucoup. J'ai beaucoup apris aujourd'hui.
J'ai encore à aprendre (voir **** dans mon code)
Voici ma version VBA:
Option Compare Database


Sub CréerRépertoire()
'1) Ajouter, par exemple, le répertoire "ClientDuMoisOctobre" dans le répertoire "c:\ClientsDe2005"
'2)Plus tard afficher à l'écran les fichiers de "c:\ClientsDe2005\ClientDuMoisOctobre"


' Test si path "ClientDuMoismm" existe'
'
' conversion du 1er caractère du mois actuel en majuscule
Dim m1, m2, mm, path1, path2, dossier, fichiers, fso, f1, fso1, f2, fichier, folder
m1 = DatePart("m", Date)
m2 = Array("", "janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre")
mm = m2(m1)
mois = UCase(Left(mm, 1)) & Mid(mm, 2)
'msgbox "mois windows: " & mm &vbCrLf&"mois modifié : " & mois


' vérification des répertoires
path1 = "d:\ClientsDe" & Year(Date) & ""
path2 = path1 & "ClientDuMois" & mois & ""


Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(path1)


If Not fso.FolderExists(path2) Then
Set g = fso.CreateFolder(path2)
' msgBox "Création du répertoire " & path2 & " effectuée" &vbCrLf&vbCrLf& "Copie des fichiers du répertoire " & path1 &vbCrLf& "vers " & path2 & " effectuée",vbInformation
End If
'****ici je veux lire les répertoires contenus dans path1
For Each folder In f.folders
Set g = fso.GetFolder(path1 & folder)
'*****ici trouver les noms des fichier pour chaque répertoire
For Each fichier In g.Files
' à écrire dans une table (à venir0
Debug.Print path1 & folder & "" & fichier.Name
Next
Next
Set fso = Nothing
End Sub

----------------------
Sub OuvrirExplorer()
Dim wshShell
'Set wshShell = Application.CreateObject("WScript.Shell")
'Dim xlApp As Object ' Declare variable to hold the reference.

Set wshShell = CreateObject("WScript.Shell")


wshShell.Run "C:\WINDOWS\EXPLORER.EXE /n,/e," & path2



End Sub

ORDINOORDINO
0
cs_jeanmarc Messages postés 34 Date d'inscription mardi 18 juin 2002 Statut Membre Dernière intervention 22 novembre 2005
27 oct. 2005 à 17:04
' Test si path "ClientDuMoismm" existe'
'
' conversion du 1er caractère du mois actuel en majuscule
Dim m1, m2, mm, path1, path2, dossier, fichiers
Dim fso, f1, fichier, Subfichier, Resultat
m1 = DatePart("m", Date)
m2 = Array("","Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre")
mm = m2(m1)
'msgbox mm


' vérification des répertoires
path1 = "d:\ClientsDe" & Year(Date) & ""
path2 = path1 & "ClientDuMois" & mm & ""
'msgbox Path1 &vbCrLf& path2


Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(path1)


If Not fso.FolderExists(path2) Then
Set f = fso.CreateFolder(path2)
Else
End if
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'lecture des répertoires contenus dans path1
For Each Subfichier in f.SubFolders
' msgbox "vérification du nom du répertoire traité: " & Subfichier
'lecture des fichiers contenus les sous-répertoires de path1
set f1 = Subfichier.Files
For Each fichier in f1
Resultat = Resultat & vbcrlf & vbcrlf & fichier
Next
Next
'msgBox Resultat


Dim wshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
Verif = WshShell.Popup(Resultat & vbcrlf & vbcrlf, 20, "Le répertoire " & Path1 & " contient les sous-répertoires et fichiers suivants: ")


Set fso = Nothing
wscript.quit
0
Rejoignez-nous