Drives ricerca

di il
11 risposte

Drives ricerca

Buongiorno quello che vorrei fare è ottenere la lista dei drives del pc o almeno sapere se uno esiste io ho scritto il seguente codice: il problema è che ni risponde sempre false..... Grazie

drives = File.GetDirectories("C:\") '.GetDrives()
     driveLettera = "C:\"
     ' Sostituisci con la lettera del drive che vuoi controllare ***************************************************************** DA FARE

     seEsiste = Array.ContainsValue(drives, driveLettera)
     
       
     If seEsiste = "true" Then
     GraphicsWindow.ShowMessage("Il drive " + driveLettera + " esiste.","Drive")
     Else
     GraphicsWindow.ShowMessage("Il drive " + driveLettera + " non esiste.","Drive")
      EndIf

11 Risposte

  • Re: Drives ricerca

    Non usare ContainsValue e File.GetDirectories...

    prova per esempio in questo modo:

    drives = File.GetDrives()
    driveLettera = "C:\"
    seEsiste = "false"
    
    For i = 1 To Array.GetItemCount(drives)
      If drives[i] = driveLettera Then
        seEsiste = "true"
      EndIf
    EndFor
    
    If seEsiste = "true" Then
      GraphicsWindow.ShowMessage("Il drive " + driveLettera + " esiste.", "Drive")
    Else
      GraphicsWindow.ShowMessage("Il drive " + driveLettera + " non esiste.", "Drive")
    EndIf
    
  • Re: Drives ricerca

    Di che linguaggio parliamo @panfra?

    È small basic?

  • Re: Drives ricerca

    05/06/2025 - panfra ha scritto:

    Array.ContainsValue(drives, driveLettera)

    Restituisce vero o falso come valore booleano non come stringa

    05/06/2025 - panfra ha scritto:

    If seEsiste = "true" Then

    Andrebbe scritto if seesite=true then... senza apici altrimenti l'espressione è sempre falsa.

    Oppure in forma breve

    If (seesiste) then...

    o direttamente

    If (Array.ContainsValue(drives, driveLettera)) then
       GraphicsWindow.ShowMessage("Il drive " + driveLettera + " esiste.","Drive")
    Else
       GraphicsWindow.ShowMessage("Il drive " + driveLettera + " non esiste.","Drive")
    EndIf
  • Re: Drives ricerca

    Nella risposta di By65Franco small basic mi dice che getdrives non esiste nel linguaggio.

    nella risposta di sihandrea mi dice che il drive C non esiste :

      drives = File.GetDirectories("C:\") '.( GetDrives() non esiste?)
         driveLettera = "C:\"
        
        If (Array.ContainsValue(drives, driveLettera)) then
       GraphicsWindow.ShowMessage("Il drive " + driveLettera + " esiste.","Drive")
    Else
       GraphicsWindow.ShowMessage("Il drive " + driveLettera + " non esiste.","Drive")
    EndIf
  • Re: Drives ricerca

    Si, in small basic la funzione non esiste...al massimo dovresti crearla.

    A quella soluzione che ti ha dato franco sostituisci

    driveLettera = "C:\"

    Con

    driveLettera = "C:"

    Small basic riconosce le unità come a:, b: c: ecc...

  • Re: Drives ricerca

    06/06/2025 - panfra ha scritto:

    Nella risposta di By65Franco small basic mi dice che getdrives non esiste nel linguaggio.

    beh, ho visto che avevi remmato le getdrives , quindi bastava utilizzarla.
    Questo vuol dire che hai solo la versione base e non hai caricato nessuna estensione con comandi/funzioni extra.

    Con precisione  potresti dire lo scopo ultimo della funzione che stai scrivendo ? grazie.

    Magari conviene usare tecniche diverse .

  • Re: Drives ricerca

    @panfra, a parte il fatti che non mi avevi risposto alla domanda che ti avevo fatto, il semplice codice dovrebbe essere

    driveLettera ="Z"
    
    drives = File.GetDirectories(driveLettera + ":\")
    If drives = "FAILED" Then
        GraphicsWindow.ShowMessage("Il drive " + driveLettera + " NON esiste.","Drive")
    Else
       GraphicsWindow.ShowMessage("Il drive " + driveLettera + " esiste.","Drive")
    EndIf
  • Re: Drives ricerca

    Il codice serve per aprire e/o salvare un file. Io lo faccio graficamente e lascio scegliere il drive su cui effettuare l'operazione all'utente. Essendoci piu' drive disponibili avrei bisogno di una loro lista o di sapere se un drive esiste o no. Tuttto qui.

  • Re: Drives ricerca

    E quindi? 

    Hai visto il codice he ti ho proposto?

    Lo hai provato?

    P.S. Se scrivi libri su Small Basic queste cose le dovresti conoscere ...

  • Re: Drives ricerca

    Grazie Oregon non avevo fatto troppo caso al tuo codice e non provandolo non ero arrivato alla conclusione che funziona. grazie ancora.

  • Re: Drives ricerca

    Di nulla ... certo non fare caso alle risposte in una discussione che hai aperto tu ... significa essere veramente distratti ... 

Devi accedere o registrarti per scrivere nel forum
11 risposte