Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Short & Long Path

6 réponses
Avatar
John Fuss
Bonjour,

j'ai un chemin de type C:\DOCUME~1\TOTO~1\LOCALS~1\Temp
et je voudrai C:\Documents and Settings\toto_est_mon_nom\Local Settings\Temp

comment faire ?

Merci d'avance.

John

6 réponses

Avatar
papou
Bonjour
Pas sûr de comprendre ta question.
Tu veux trouver un moyen pour renvoyer avec le User le chemin vers Local
SettingsTemp ?
Si c'est le cas, une fonction API pourrait t'aider pour ça :
GetUserProfileDirectory
Mais comme je ne suis pas sûr...
Cordialement
Pascal

"John Fuss" a écrit dans le message de news:
cpmjhe$u9e$
Bonjour,

j'ai un chemin de type C:DOCUME~1TOTO~1LOCALS~1Temp
et je voudrai C:Documents and Settingstoto_est_mon_nomLocal
SettingsTemp

comment faire ?

Merci d'avance.

John




Avatar
Frédéric Sigonneau
Bonjour,

Un code Microsoft qui devrait te dépanner :

'======================= Sub testt()
ShortName = "C:DOCUME~1DEFAUL~1LOCALS~1Temp"
MsgBox GetLongFN(ShortName)
End Sub


Function GetLongFN(ByVal sShortName As String) As String
Dim sLongName As String, sTemp As String, iSlashPos As Integer

'Add to short name to prevent Instr from failing
sShortName = sShortName & ""
'Start from 4 to ignore the "[Drive Letter]:" characters
iSlashPos = InStr(4, sShortName, "")

'Pull out each string between character for conversion
While iSlashPos
sTemp = Dir(Left$(sShortName, iSlashPos - 1), _
vbNormal + vbHidden + vbSystem + vbDirectory)
'Error 52 - Bad File Name or Number
If sTemp = "" Then
GetLongFN = ""
Exit Function
End If
sLongName = sLongName & "" & sTemp
iSlashPos = InStr(iSlashPos + 1, sShortName, "")
Wend
'Prefix with the drive letter
GetLongFN = Left$(sShortName, 2) & sLongName

End Function
'=======================
FS
---
Frédéric Sigonneau [MVP Excel - né un sans-culottide]
Gestions de temps, VBA pour Excel :
http://frederic.sigonneau.free.fr
Si votre question sur Excel est urgente, évitez ma bal !

Bonjour,

j'ai un chemin de type C:DOCUME~1TOTO~1LOCALS~1Temp
et je voudrai C:Documents and Settingstoto_est_mon_nomLocal SettingsTemp

comment faire ?

Merci d'avance.

John




Avatar
John Fuss
Merci bcp, c'est exactement ça.

John.

"Frédéric Sigonneau" a écrit dans le message de
news:%
Bonjour,

Un code Microsoft qui devrait te dépanner :

'======================= > Sub testt()
ShortName = "C:DOCUME~1DEFAUL~1LOCALS~1Temp"
MsgBox GetLongFN(ShortName)
End Sub


Function GetLongFN(ByVal sShortName As String) As String
Dim sLongName As String, sTemp As String, iSlashPos As Integer

'Add to short name to prevent Instr from failing
sShortName = sShortName & ""
'Start from 4 to ignore the "[Drive Letter]:" characters
iSlashPos = InStr(4, sShortName, "")

'Pull out each string between character for conversion
While iSlashPos
sTemp = Dir(Left$(sShortName, iSlashPos - 1), _
vbNormal + vbHidden + vbSystem + vbDirectory)
'Error 52 - Bad File Name or Number
If sTemp = "" Then
GetLongFN = ""
Exit Function
End If
sLongName = sLongName & "" & sTemp
iSlashPos = InStr(iSlashPos + 1, sShortName, "")
Wend
'Prefix with the drive letter
GetLongFN = Left$(sShortName, 2) & sLongName

End Function
'======================= >
FS
---
Frédéric Sigonneau [MVP Excel - né un sans-culottide]
Gestions de temps, VBA pour Excel :
http://frederic.sigonneau.free.fr
Si votre question sur Excel est urgente, évitez ma bal !

Bonjour,

j'ai un chemin de type C:DOCUME~1TOTO~1LOCALS~1Temp
et je voudrai C:Documents and Settingstoto_est_mon_nomLocal
SettingsTemp



comment faire ?

Merci d'avance.

John






Avatar
John Fuss
c'etait pour depuis un chemin en mode 'dos' avec des tildes j'obtienne un
chemin en mode 'windows'.

Mais Frederic Sigonneau a repondu. Merci

John

"papou" <cestpasbon@çanonplus44.fr> a écrit dans le message de
news:
Bonjour
Pas sûr de comprendre ta question.
Tu veux trouver un moyen pour renvoyer avec le User le chemin vers Local
SettingsTemp ?
Si c'est le cas, une fonction API pourrait t'aider pour ça :
GetUserProfileDirectory
Mais comme je ne suis pas sûr...
Cordialement
Pascal

"John Fuss" a écrit dans le message de news:
cpmjhe$u9e$
Bonjour,

j'ai un chemin de type C:DOCUME~1TOTO~1LOCALS~1Temp
et je voudrai C:Documents and Settingstoto_est_mon_nomLocal
SettingsTemp

comment faire ?

Merci d'avance.

John








Avatar
papou
Ok, j'ai vu effectivement et je garde aussi précieusement ;-)
Cordialement
Pascal

"John Fuss" a écrit dans le message de news:
cpmt9s$6fd$
c'etait pour depuis un chemin en mode 'dos' avec des tildes j'obtienne un
chemin en mode 'windows'.

Mais Frederic Sigonneau a repondu. Merci

John

"papou" <cestpasbon@çanonplus44.fr> a écrit dans le message de
news:
Bonjour
Pas sûr de comprendre ta question.
Tu veux trouver un moyen pour renvoyer avec le User le chemin vers Local
SettingsTemp ?
Si c'est le cas, une fonction API pourrait t'aider pour ça :
GetUserProfileDirectory
Mais comme je ne suis pas sûr...
Cordialement
Pascal

"John Fuss" a écrit dans le message de news:
cpmjhe$u9e$
Bonjour,

j'ai un chemin de type C:DOCUME~1TOTO~1LOCALS~1Temp
et je voudrai C:Documents and Settingstoto_est_mon_nomLocal
SettingsTemp

comment faire ?

Merci d'avance.

John












Avatar
Alain CROS
Bonjour

Il y avait quelque temps que je n'avais pas utilisé les API.

Private Declare Function GetShortPathName& Lib "kernel32" Alias "GetShortPathNameA" _
(ByVal lpszLongPath$, ByVal lpszShortPath$, ByVal cchBuffer&)
Private Declare Function GetLongPathName& Lib "kernel32" Alias "GetLongPathNameA" _
(ByVal lpszShortPath$, ByVal lpszLongPath$, ByVal cchBuffer&)


Sub Demo()
Dim LongName$, I&, ShortName$, J&, k&, LongBuff$, ShortBuff$
ShortName = "Test.txt"
LongName = CurDir & Application.PathSeparator & ShortName
If Dir(LongName) = "" Then
MsgBox "Le fichier " & ShortName & " n'existe pas !"
Exit Sub
End If
I = Len(LongName)
ShortBuff = Space$(I)
J = GetShortPathName(LongName, ShortBuff, I)
ShortName = Left$(ShortBuff, J)
MsgBox "Nom court :" & vbNewLine & vbNewLine & ShortName
k = Len(ShortName) * 2&
LongBuff = Space$(k)
k = GetLongPathName(ShortName, LongBuff, k)
MsgBox "Nom long :" & vbNewLine & vbNewLine & Left$(LongBuff, k)
End Sub

Alain CROS

"John Fuss" a écrit dans le message de news: cpmjhe$u9e$
Bonjour,

j'ai un chemin de type C:DOCUME~1TOTO~1LOCALS~1Temp
et je voudrai C:Documents and Settingstoto_est_mon_nomLocal SettingsTemp

comment faire ?

Merci d'avance.

John