Code-Beispiel
		
Dateien und Ordner suchen
| Lizenz: | Erster Autor: | Letzte Bearbeitung: | 
| k. A. |  hhr |   03.10.2020 | 
Hier wird der Versuch gemacht, in einem Konsolenprogramm Pfadangaben zu verarbeiten, die sämtliche Zeichen enthalten dürfen, die in Windows erlaubt sind.
Dafür wird die Zeichentabelle von Windows verwendet. Nur für die Print-Anweisung wird die OEM-Tabelle eingeschaltet.
CHCP:
#Include "windows.bi" ' GetACP, GetOEMCP
Print "OEM Code Page: ";GetOEMCP
Print "ANSI Code Page: ";GetACP
Print String(20,"-")
Dim As String searchstring,path,pathname,_name
Dim As Byte result
Dim As Integer attribute
Shell "CHCP " & Str(GetACP) & " > NUL"
Print "Zu durchsuchenden Pfad eingeben: ";
Line Input path
path = Trim(path,Any Chr(32,34))
Shell "CHCP " & Str(GetOEMCP) & " > NUL"
Print Wstr(path)
Shell "CHCP " & Str(GetACP) & " > NUL"
Print
Print "Gesamter oder Teil des Namens: ";
Line Input searchstring
searchstring = Trim(searchstring,Any Chr(32,34))
Shell "CHCP " & Str(GetOEMCP) & " > NUL"
Print Wstr(searchstring)
Shell "CHCP " & Str(GetACP) & " > NUL"
searchstring = Lcase(searchstring)
Print String(20,"-")
Open Pipe "DIR /B /S " & Chr(34) & path & Chr(34) For Input As #1
   Do Until Eof(1)
      Line Input #1,pathname
      _name = Dir(pathname,&hFF,attribute)
      _name = Lcase(_name)
      If Instr(_name,searchstring) > 0 Then
         Shell "CHCP " & Str(GetOEMCP) & " > NUL"
         If Bit(attribute,4) = 0 Then
            Print "Datei:"
            Print Wstr(pathname)
         Else
            Print "Ordner:"
            Print Wstr(pathname)
         End If
         Shell "CHCP " & Str(GetACP) & " > NUL"
         result = 1
         Print
      End If
   Loop
Close #1
Shell "CHCP " & Str(GetOEMCP) & " > NUL"
If result = 0 Then Print Wstr("Es wurde keine Übereinstimmung gefunden.")
Print
Print "Ende mit beliebiger Taste..."
Sleep
End 'findfile.bas
'
SetConsoleCP, SetConsoleOutputCP:
#Include "windows.bi" ' GetACP, GetOEMCP, SetConsoleOutputCP, SetConsoleCP
Print "OEM Code Page: ";GetOEMCP
Print "ANSI Code Page: ";GetACP
Print String(20,"-")
Dim As String searchstring,path,pathname,_name
Dim As Byte result
Dim As Integer attribute
SetConsoleOutputCP(GetACP)
SetConsoleCP(GetACP)
Print "Zu durchsuchenden Pfad eingeben: ";
Line Input path
path = Trim(path,Any Chr(32,34))
SetConsoleOutputCP(GetOEMCP)
Print Wstr(path)
SetConsoleOutputCP(GetACP)
Print
Print "Gesamter oder Teil des Namens: ";
Line Input searchstring
searchstring = Trim(searchstring,Any Chr(32,34))
SetConsoleOutputCP(GetOEMCP)
Print Wstr(searchstring)
SetConsoleOutputCP(GetACP)
searchstring = Lcase(searchstring)
Print String(20,"-")
Open Pipe "DIR /B /S " & Chr(34) & path & Chr(34) For Input As #1
   Do Until Eof(1)
      Line Input #1,pathname
      _name = Dir(pathname,&hFF,attribute)
      _name = Lcase(_name)
      If Instr(_name,searchstring) > 0 Then
         If Bit(attribute,4) = 0 Then
            Print "Datei:"
            SetConsoleOutputCP(GetOEMCP)
            Print Wstr(pathname)
            SetConsoleOutputCP(GetACP)
         Else
            Print "Ordner:"
            SetConsoleOutputCP(GetOEMCP)
            Print Wstr(pathname)
            SetConsoleOutputCP(GetACP)
         End If
         result = 1
         Print
      End If
   Loop
Close #1
SetConsoleOutputCP(GetOEMCP)
If result = 0 Then Print Wstr("Es wurde keine Übereinstimmung gefunden.")
Print
Print "Ende mit beliebiger Taste..."
'SetConsoleCP(GetOEMCP)
Sleep
End 'findfile.bas
'Dank an nemored und grindstone:
https://forum.qbasic.at/viewtopic.php?p=110592&sid=902b9adebcfc5d8d8f8bf92947ae5426#110592
		
		| Zusätzliche Informationen und Funktionen | 
		
			
				
					- Das Code-Beispiel wurde am 21.09.2020 von 
 hhr angelegt. 
					- Die aktuellste Version wurde am 03.10.2020 von 
 hhr gespeichert. 
					
				 
			 | 
			
				 
				 
			 |