IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBScript Discussion :

Problème d'espaces dans un dossier à choisir


Sujet :

VBScript

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Expert confirmé
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 844
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 844
    Par défaut Problème d'espaces dans un dossier à choisir

    suite à cette discussion Variable Input Type Password ,ce petit HTA pour la compression et la sauvegarde avec 7zip a vu le jour ; mais il y a un petit bug c'est qu'on passant les paramètres du dossier à choisir il faut qu'il soit sans espaces.
    Alors je cherche un truc ou une astuce pour contourner ce problème d'espaces.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    <html>
    <head>
    <SCRIPT LANGUAGE="VBScript">
    '=========================================================
    'Fenêtre pour choisir le répertoire cible de la sauvegarde
    '=========================================================
    Const WINDOW_HANDLE = 0
    BIF_editbox = &H0010
    titre="Sélectionner la destination de la sauvegarde"
    CenterWindow 260,180
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.BrowseForFolder _
        (WINDOW_HANDLE, titre , BIF_editbox)
    On Error Resume Next
    Set objFolderItem = objFolder.Self
    If Err <> 0 Then
            msgbox "Annulation de la sauvegarde",48,"Annulation de la sauvegarde"
            fermer()
    Else
            objPath = objFolderItem.Path
     
    end If
     
    sub compression
    Set WshShell = CreateObject("WScript.Shell")
    Set fso = CreateObject("Scripting.FileSystemObject")
    oProgramFiles = WshShell.ExpandEnvironmentStrings("%PROGRAMFILES%")
    chemin7zip = oProgramFiles &"\7-zip\7z.exe"
    If Not fso.FileExists(chemin7zip) Then
    MsgBox "Le " & chemin7zip & " n'existe pas",48,chemin7zip
    WshShell.Run "http://www.spiroo.be/7zip/"
    Call Fermer
    Else
    strCMD = "cmd /c cd %PROGRAMFILES%\7-zip & 7z.exe"
    password = pass.value
    MsgBox "Vous avez choisi le dossier " & qq(objPath) & " pour la sauvegarde",64,"Dossier Choisi "& qq(objPath)&"" 
    Str7zip = strCMD & " u " & objPath &"\sauvegarde.zip " & objPath & " -p"&password
    MsgBox Str7zip,64," Commande à exécuter !"
    WshShell.Run Str7zip,1,True
    MsgBox "L'archive : " & objPath &"\sauvegarde.zip est Crée avec Succès ! ",64,"sauvegarde.zip est Crée avec Succès !" 
    Call Fermer
    End If
    End Sub
     
    Sub CenterWindow(x,y)        
    window.resizeTo x,y      
    iLeft = window.screen.availWidth/2 - x/2       
    itop = window.screen.availHeight/2 - y/2    
    window.moveTo ileft, itop      
    End Sub    
     
    Sub Fermer
    window.close()
    End Sub
     
    Function qq(strIn)
        qq = Chr(34) & strIn & Chr(34)
    End Function
    </script>
    </head>
    <title>Sauvegarde avec l'utilitaire 7-Zip</title>    
    <HTA:APPLICATION ID="Sauvegarde avec l'utilitaire 7-Zip"
    APPLICATIONNAME="Sauvegarde avec l'utilitaire 7-Zip"
    CAPTION="Yes"
    SHOWINTASKBAR="No"
    SINGLEINSTANCE="yes"
    SYSMENU="No"
    SCROLL="no"
    WINDOWSTATE="normal">
    <center>
    <body BGCOLOR="lightblue">
    Mot de passe OBLIGATOIRE : <input type="password" size="20" name="pass" ID="pass"><br><br>
    <input type="submit" id="BTvalider" name="valider" value="Continuer" onclick="compression()">
    <input type="button" id="Fermer" value="Fermer" onclick="Fermer()">
    </body>
    </html>

  2. #2
    Expert confirmé
    Avatar de ProgElecT
    Homme Profil pro
    Retraité
    Inscrit en
    Décembre 2004
    Messages
    6 130
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 69
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Retraité
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Décembre 2004
    Messages : 6 130
    Par défaut
    Salut
    mais il y a un petit bug c'est qu'on passant les paramètres du dossier à choisir il faut qu'il soit sans espaces.
    Tu parles de la ligne 37 utilisée dans la commande ligne 37 ?
    Peut être remplacer les espaces par %20 comme pour les URLs ?
    :whistle:pourquoi pas, pour remercier, un :plusser: pour celui/ceux qui vous ont dépannés.
    saut de ligne
    OOOOOOOOO👉 → → Ma page perso sur DVP ← ← 👈

  3. #3
    Expert confirmé
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 844
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 844
    Par défaut
    Citation Envoyé par ProgElecT Voir le message
    Salut
    Tu parles de la ligne 37 utilisée dans la commande ligne 37 ?

    Oui exactement le problème vient de la commande DOS à passer dans la ligne 37 car en DOS on n'accepte pas les espaces ou les caractères accentuées

  4. #4
    Expert confirmé
    Avatar de ProgElecT
    Homme Profil pro
    Retraité
    Inscrit en
    Décembre 2004
    Messages
    6 130
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 69
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Retraité
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Décembre 2004
    Messages : 6 130
    Par défaut
    Je ne sais pas si tu as vue l'ajout dans mon post précédant, j'ai cette routine que j'utilise aussi bien en VBScript que VB6, si cela peut être utile
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    dim CharSpc(10), CharCod(10)
    'A complèté
    CharSpc(0) = " ": CharCod(0) = "%20"
    CharSpc(1) = "µ": CharCod(1) = "%C2%B5"
    CharSpc(2) = "à": CharCod(2) = "%C3%A0"
    CharSpc(3) = "â": CharCod(3) = "%C3%A2"
    CharSpc(4) = "ê": CharCod(4) = "%C3%AA"
    CharSpc(5) = "ç": CharCod(5) = "%C3%A7"
    CharSpc(6) = "è": CharCod(6) = "%C3%A8"
    CharSpc(7) = "é": CharCod(7) = "%C3%A9"
    CharSpc(8) = "ë": CharCod(8) = "%C3%AB"
    CharSpc(9) = "ô": CharCod(9) = "%C3%B4"
    CharSpc(10) = "ø": CharCod(10) = "%C3%B8"
     
    '...................................................................................
    Function EncodeURI(StrAencoder)
    Dim cpT
    EncodeURI = StrAencoder
    For cpT = 0 To UBound(CharSpc)
        EncodeURI = Replace(EncodeURI, CharSpc(cpT), CharCod(cpT), 1, -1, vbTextCompare)
    Next
    End Function
    '...................................................................................
    Function DecodeURI(StrAdecoder)
    Dim cpT
    DecodeURI = StrAdecoder
    For cpT = 0 To UBound(CharCod)
        DecodeURI = Replace(DecodeURI, CharCod(cpT), CharSpc(cpT), 1, -1, vbTextCompare)
    Next
    End Function
    '...................................................................................
     
    Dim Msg
    Msg = EncodeURI("Ceci est une chaîne encodée")
    MsgBox "Ceci est une chaîne encodée" & vbCrLf _
            & Msg, vbInformation,"Equivalence de EncodeURI de JScript"
     
    Msg = DecodeURI(Msg)
    MsgBox "Et voici l'inverse de, ""Ceci%20est%20une%20chaîne%20encod%C3%A9e""" & vbCrLf _
            & Msg, vbInformation,"Equivalence de DecodeURI de JScript"
    :whistle:pourquoi pas, pour remercier, un :plusser: pour celui/ceux qui vous ont dépannés.
    saut de ligne
    OOOOOOOOO👉 → → Ma page perso sur DVP ← ← 👈

  5. #5
    Expert confirmé
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 844
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 844
    Par défaut
    Citation Envoyé par ProgElecT Voir le message
    Je ne sais pas si tu as vue l'ajout dans mon post précédant, j'ai cette routine que j'utilise aussi bien en VBScript que VB6, si cela peut être utile
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    dim CharSpc(10), CharCod(10)
    'A complèté
    CharSpc(0) = " ": CharCod(0) = "%20"
    CharSpc(1) = "µ": CharCod(1) = "%C2%B5"
    CharSpc(2) = "à": CharCod(2) = "%C3%A0"
    CharSpc(3) = "â": CharCod(3) = "%C3%A2"
    CharSpc(4) = "ê": CharCod(4) = "%C3%AA"
    CharSpc(5) = "ç": CharCod(5) = "%C3%A7"
    CharSpc(6) = "è": CharCod(6) = "%C3%A8"
    CharSpc(7) = "é": CharCod(7) = "%C3%A9"
    CharSpc(8) = "ë": CharCod(8) = "%C3%AB"
    CharSpc(9) = "ô": CharCod(9) = "%C3%B4"
    CharSpc(10) = "ø": CharCod(10) = "%C3%B8"
     
    '...................................................................................
    Function EncodeURI(StrAencoder)
    Dim cpT
    EncodeURI = StrAencoder
    For cpT = 0 To UBound(CharSpc)
        EncodeURI = Replace(EncodeURI, CharSpc(cpT), CharCod(cpT), 1, -1, vbTextCompare)
    Next
    End Function
    '...................................................................................
    Function DecodeURI(StrAdecoder)
    Dim cpT
    DecodeURI = StrAdecoder
    For cpT = 0 To UBound(CharCod)
        DecodeURI = Replace(DecodeURI, CharCod(cpT), CharSpc(cpT), 1, -1, vbTextCompare)
    Next
    End Function
    '...................................................................................
     
    Dim Msg
    Msg = EncodeURI("Ceci est une chaîne encodée")
    MsgBox "Ceci est une chaîne encodée" & vbCrLf _
            & Msg, vbInformation,"Equivalence de EncodeURI de JScript"
     
    Msg = DecodeURI(Msg)
    MsgBox "Et voici l'inverse de, ""Ceci%20est%20une%20chaîne%20encod%C3%A9e""" & vbCrLf _
            & Msg, vbInformation,"Equivalence de DecodeURI de JScript"
    pour ces fonctions j'ai essayé comme ceci mais hélas ça n'a pas marché
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    <html>
    <head>
    <SCRIPT LANGUAGE="VBScript">
    '=========================================================
    'Fenêtre pour choisir le répertoire cible de la sauvegarde
    '=========================================================
    Const WINDOW_HANDLE = 0
    BIF_editbox = &H0010
    titre="Sélectionner la destination de la sauvegarde"
    CenterWindow 260,180
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.BrowseForFolder _
        (WINDOW_HANDLE, titre , BIF_editbox)
    On Error Resume Next
    Set objFolderItem = objFolder.Self
    If Err <> 0 Then
            msgbox "Annulation de la sauvegarde",48,"Annulation de la sauvegarde"
            fermer()
    Else
            objPath = EncodeURI(objFolderItem.Path)
     
    end If
     
    sub compression
    Set WshShell = CreateObject("WScript.Shell")
    Set fso = CreateObject("Scripting.FileSystemObject")
    oProgramFiles = WshShell.ExpandEnvironmentStrings("%PROGRAMFILES%")
    chemin7zip = oProgramFiles &"\7-zip\7z.exe"
    If Not fso.FileExists(chemin7zip) Then
    MsgBox "Le " & chemin7zip & " n'existe pas",48,chemin7zip
    WshShell.Run "http://www.spiroo.be/7zip/"
    Call Fermer
    Else
    strCMD = "cmd /K cd %PROGRAMFILES%\7-zip & 7z.exe"
    password = pass.value
    MsgBox "Vous avez choisi le dossier " & qq(objPath) & " pour la sauvegarde",64,"Dossier Choisi "& qq(objPath)&"" 
    Str7zip = strCMD & " u " & objPath &"\sauvegarde.zip " & objPath & " -p"&password
    MsgBox Str7zip,64," Commande à exécuter !"
    WshShell.Run Str7zip,1,True
    MsgBox "L'archive : " & objPath &"\sauvegarde.zip est Crée avec Succès ! ",64,"sauvegarde.zip est Crée avec Succès !" 
    Call Fermer
    End If
    End Sub
     
    Sub CenterWindow(x,y)        
    window.resizeTo x,y      
    iLeft = window.screen.availWidth/2 - x/2       
    itop = window.screen.availHeight/2 - y/2    
    window.moveTo ileft, itop      
    End Sub    
     
    Sub Fermer
    window.close()
    End Sub
     
    Function qq(strIn)
        qq = Chr(34) & strIn & Chr(34)
    End Function
     
    Function EncodeURI(StrAencoder)
    Dim cpT
    dim CharSpc(10), CharCod(10)
    CharSpc(0) = " ": CharCod(0) = "%20"
    CharSpc(1) = "µ": CharCod(1) = "%C2%B5"
    CharSpc(2) = "à": CharCod(2) = "%C3%A0"
    CharSpc(3) = "â": CharCod(3) = "%C3%A2"
    CharSpc(4) = "ê": CharCod(4) = "%C3%AA"
    CharSpc(5) = "ç": CharCod(5) = "%C3%A7"
    CharSpc(6) = "è": CharCod(6) = "%C3%A8"
    CharSpc(7) = "é": CharCod(7) = "%C3%A9"
    CharSpc(8) = "ë": CharCod(8) = "%C3%AB"
    CharSpc(9) = "ô": CharCod(9) = "%C3%B4"
    CharSpc(10) = "ø": CharCod(10) = "%C3%B8"
     
    EncodeURI = StrAencoder
    For cpT = 0 To UBound(CharSpc)
        EncodeURI = Replace(EncodeURI, CharSpc(cpT), CharCod(cpT), 1, -1, vbTextCompare)
    Next
    End Function
    </script>
    </head>
    <title>Sauvegarde avec l'utilitaire 7-Zip</title>    
    <HTA:APPLICATION ID="Sauvegarde avec l'utilitaire 7-Zip"
    APPLICATIONNAME="Sauvegarde avec l'utilitaire 7-Zip"
    CAPTION="Yes"
    SHOWINTASKBAR="No"
    SINGLEINSTANCE="yes"
    SYSMENU="No"
    SCROLL="no"
    WINDOWSTATE="normal">
    <center>
    <body BGCOLOR="lightblue">
    Mot de passe OBLIGATOIRE : <input type="password" size="20" name="pass" ID="pass"><br><br>
    <input type="submit" id="BTvalider" name="valider" value="Continuer" onclick="compression()">
    <input type="button" id="Fermer" value="Fermer" onclick="Fermer()">
    </body>
    </html>

  6. #6
    Expert confirmé
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 844
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 844
    Par défaut Résolu !

    La solution été devant moi il suffit d'appliquer la fonction qq(strIn) comme ceci et le problème d'espace est
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    objPath = qq(objFolderItem.Path)
    Function qq(strIn)
        qq = Chr(34) & strIn & Chr(34)
    End Function
    et le code final devient alors :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    <html>
    <head>
    <SCRIPT LANGUAGE="VBScript">
    '=========================================================
    'Fenêtre pour choisir le répertoire cible de la sauvegarde
    '=========================================================
    Const WINDOW_HANDLE = 0
    BIF_editbox = &H0010
    titre="Sélectionner la destination de la sauvegarde"
    CenterWindow 260,180
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.BrowseForFolder _
        (WINDOW_HANDLE, titre , BIF_editbox)
    On Error Resume Next
    Set objFolderItem = objFolder.Self
    If Err <> 0 Then
            msgbox "Annulation de la sauvegarde",48,"Annulation de la sauvegarde"
            fermer()
    Else
            objPath = qq(objFolderItem.Path)
    end If
     
    sub compression
    Set WshShell = CreateObject("WScript.Shell")
    Set fso = CreateObject("Scripting.FileSystemObject")
    oProgramFiles = WshShell.ExpandEnvironmentStrings("%PROGRAMFILES%")
    chemin7zip = oProgramFiles &"\7-zip\7z.exe"
    If Not fso.FileExists(chemin7zip) Then
    MsgBox "Le " & chemin7zip & " n'existe pas",48,chemin7zip
    WshShell.Run "http://www.spiroo.be/7zip/"
    Call Fermer
    Else
    strCMD = "cmd /K cd %PROGRAMFILES%\7-zip & 7z.exe"
    password = pass.value
    MsgBox "Vous avez choisi le dossier " & qq(objPath) & " pour la sauvegarde",64,"Dossier Choisi "& qq(objPath)&"" 
    Str7zip = strCMD & " u " & objPath &"\sauvegarde.zip " & objPath & " -p"&password
    MsgBox Str7zip,64," Commande à exécuter !"
    WshShell.Run Str7zip,1,True
    MsgBox "L'archive : " & objPath &"\sauvegarde.zip est Crée avec Succès ! ",64,"sauvegarde.zip est Crée avec Succès !" 
    Call Fermer
    End If
    End Sub
     
    Sub CenterWindow(x,y)        
    window.resizeTo x,y      
    iLeft = window.screen.availWidth/2 - x/2       
    itop = window.screen.availHeight/2 - y/2    
    window.moveTo ileft, itop      
    End Sub    
     
    Sub Fermer
    window.close()
    End Sub
     
    Function qq(strIn)
        qq = Chr(34) & strIn & Chr(34)
    End Function
    </script>
    </head>
    <title>Sauvegarde avec l'utilitaire 7-Zip</title>    
    <HTA:APPLICATION ID="Sauvegarde avec l'utilitaire 7-Zip"
    APPLICATIONNAME="Sauvegarde avec l'utilitaire 7-Zip"
    CAPTION="Yes"
    SHOWINTASKBAR="No"
    SINGLEINSTANCE="yes"
    SYSMENU="No"
    SCROLL="no"
    WINDOWSTATE="normal">
    <center>
    <body BGCOLOR="lightblue">
    Mot de passe OBLIGATOIRE : <input type="password" size="20" name="pass" ID="pass"><br><br>
    <input type="submit" id="BTvalider" name="valider" value="Continuer" onclick="compression()">
    <input type="button" id="Fermer" value="Fermer" onclick="Fermer()">
    </body>
    </html>

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème d'espace dans nom de dossier.
    Par Snooky68 dans le forum Général Python
    Réponses: 11
    Dernier message: 29/08/2008, 14h55
  2. Réponses: 8
    Dernier message: 08/02/2007, 17h46
  3. [CSS] Problème d'espaces dans une liste
    Par sylsau dans le forum Mise en page CSS
    Réponses: 3
    Dernier message: 03/08/2006, 13h46
  4. Problème d'espace dans les variables
    Par crocmorts dans le forum Langage
    Réponses: 3
    Dernier message: 26/04/2006, 15h12
  5. Problème d'espace dans les varibles passées par GET !
    Par boukay dans le forum Balisage (X)HTML et validation W3C
    Réponses: 2
    Dernier message: 07/03/2006, 14h36

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo