DESKTOP

Résolu
tekila_bandita Messages postés 248 Date d'inscription mercredi 15 juin 2005 Statut Membre Dernière intervention 15 mars 2007 - 7 août 2005 à 11:18
violent_ken Messages postés 1812 Date d'inscription mardi 31 mai 2005 Statut Membre Dernière intervention 26 octobre 2010 - 8 août 2005 à 08:11
J'aimerais copier un fichier du repertoire C: Dans le bureau (C:Documents and Settings/USER/Bureau) mais sans spécifier le nom de l' "USER"...

ex :

Set
FSys =
CreateObject
(<VAR>"Scripting.FileSystemObject"</VAR>)
Set
MonFic = FSys.GetFile(<VAR>"C:\fichier.txt"</VAR>)

MonFic.
Copy
<VAR>"C:\Documents and Settings/USER/Bureau/fichier.txt"</VAR>, True

Set FSys = nothing

7 réponses

Utilisateur anonyme
7 août 2005 à 11:43
ReBonjour,



Autre solution



Set FSys = CreateObject("Scripting.FileSystemObject")

Set MonFic = FSys.GetFile("C:\fichier.txt")

MonFic.Copy "C:\Documents and Settings/" & Environ("UserName") & "/Bureau/fichier.txt", True

Set FSys = nothing



ChRB



<hr size="2" width="100%">
Merci de cliquer sur "Réponse acceptée" si une réponse vous convient.
3
Utilisateur anonyme
7 août 2005 à 11:27
Bonjour,





Pour récupéré l'utilisateur:





Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long



Public Function UserName() As String

Dim Buffer As String * 250

Dim Size As Long: Size = 251

If GetUserName(Buffer, Size) Then UserName = Left$(Buffer, Size)

End If

End Function







Set FSys = CreateObject("Scripting.FileSystemObject")

Set MonFic = FSys.GetFile("C:\fichier.txt")

MonFic.Copy "C:\Documents and Settings/" & UserName & "/Bureau/fichier.txt", True

Set FSys = nothing









ChRB
<hr size="2" width="100%">
Merci de cliquer sur "Réponse acceptée" si une réponse vous convient.
0
tekila_bandita Messages postés 248 Date d'inscription mercredi 15 juin 2005 Statut Membre Dernière intervention 15 mars 2007 33
7 août 2005 à 11:32
C'est pas normal,"ligne 1 caractere 17, fin d'instruction attendu "!
pourtant, le caractere 17 est la fin de "function"
....
merci quand meme...
je pense que ça vient de moi, donc il me faudait un autre code...
0
Utilisateur anonyme
7 août 2005 à 11:41
Bonjour,



Pardon, j'ai mis un "End If" en trop







Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Public Function UserName() As String
Dim Buffer As String * 250
Dim Size As Long: Size = 251
If GetUserName(Buffer, Size) Then UserName = Left$(Buffer, Size)
End Function


Set FSys = CreateObject("Scripting.FileSystemObject")
Set MonFic = FSys.GetFile("C:\fichier.txt")
MonFic.Copy "C:\Documents and Settings/" & UserName & "/Bureau/fichier.txt", True
Set FSys = nothing

ChRB
<hr size="2" width="100%">
Merci de cliquer sur "Réponse acceptée" si une réponse vous convient.
0

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

Posez votre question
tekila_bandita Messages postés 248 Date d'inscription mercredi 15 juin 2005 Statut Membre Dernière intervention 15 mars 2007 33
7 août 2005 à 13:51
J'ai trouvé comment résoudre mon probleme grace a la magnifique source de philheiz: fonction environ en vbscript.
il me suffit d'ajouter :


Function
Environ
(VarName)
Dim
wss, env
Set
wss =
CreateObject
(<VAR>"WScript.Shell"</VAR>)
Set
env = wss.environment(<VAR>"process"</VAR>)
Environ
= env(VarName)
If
Environ
= <VAR>""</VAR>
Then

Set
env = wss.environment(<VAR>"system"</VAR>)
Environ
= env(VarName)
End
If

End
Function


au deuxieme code que Charles Racaud m'a donné pour pouvoir utiliser la fonction environ.
MERCI BEAUCOUP !
probleme: je ne comprend pas tout a cette source...
donc je suis obliger d'avoué mon lamentable copier collé !
;)
0
cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 130
7 août 2005 à 14:29
Et oui, il existe quelques sources sur le site qui parle de cà, une recherche aurait permis de se passer du forum...

DarK Sidious

Un API Viewer (pour le VB, VB.NET, C, C# et Delphi) : www.ProgOtoP.com/popapi/
0
violent_ken Messages postés 1812 Date d'inscription mardi 31 mai 2005 Statut Membre Dernière intervention 26 octobre 2010 2
8 août 2005 à 08:11
Violent Ken


Une autre solution, voir les répertoires spéciaux de windows avec une api :

'coller ça dans un module
'constantes pour les path particuliers
Const CSIDL_DESKTOP = &H0
Const CSIDL_PROGRAMS = &H2
Const CSIDL_CONTROLS = &H3
Const CSIDL_PRINTERS = &H4
Const CSIDL_PERSONAL = &H5
Const CSIDL_FAVORITES = &H6
Const CSIDL_STARTUP = &H7
Const CSIDL_RECENT = &H8
Const CSIDL_SENDTO = &H9
Const CSIDL_BITBUCKET = &HA
Const CSIDL_STARTMENU = &HB
Const CSIDL_DESKTOPDIRECTORY = &H10
Const CSIDL_DRIVES = &H11
Const CSIDL_NETWORK = &H12
Const CSIDL_NETHOOD = &H13
Const CSIDL_FONTS = &H14
Const CSIDL_TEMPLATES = &H15
Const MAX_PATH = 260
Private Type SHITEMID
cb As Long
abID As Byte
End Type
Private Type ITEMIDLIST
mkid As SHITEMID
End Type
Public Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
Public Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long


Public Function GetSpecialfolder(CSIDL As Long) As String
'fonction permettant d'avoir le chemin de certains dossiers comme
'Mes documents, ou Bureau
'Et oui, tout le monde ne s'appelle pas pareil (n'oublions pas que mes documents
'se trouve dans documents and settings\VOTRE NOM\mes documents) et que tout
'le monde n'a pas le même nom de volume (bien que ce soit C:\ en général)
Dim R As Long
Dim IDL As ITEMIDLIST
'Get the special folder
R = SHGetSpecialFolderLocation(100, CSIDL, IDL)
If R = NOERROR Then
'Create a buffer
Path$ = Space$(512)
'Get the path from the IDList
R = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal Path$)
'Remove the unnecessary chr$(0)'s
GetSpecialfolder = Left$(Path, InStr(Path, Chr$(0)) - 1)
Exit Function
End If
GetSpecialfolder = ""
End Function

'et ça dans une form
Private Sub Form_Load()
MsgBox GetSpecialfolder(&H10)
End Sub
0
Rejoignez-nous