'*** v9.4 *** www.dieseyer.de ******************************* ' ' File: DateiNamenLangVBS.vbs ' Autor: dieseyer@gmx.de ' dieseyer.de ' ' Sucht im Zielverzeichnis nach Dateien, deren Name inkl. ' kompletter Pfadangabe länger als 250 Zeichen ist. ' Seit v9.4 mit 'Browse For Folder', wenn die Variable ' "LaufWerk" leer ist. ' '*********************************************************** Option Explicit ' Siehe http://dieseyer.de/dse-wsh-lernen.html#OptionExpl Dim TmpTmp, Text, i, iDatei, iVerz, iLang, iAnz, MaxAnz, LaufWerk, Modus1, Modus2, Zeit Dim WSHShell, fso, fi Set WSHShell = WScript.CreateObject("WScript.Shell") Set fso = WScript.CreateObject("Scripting.FileSystemObject") iLang = 0 Modus1 = 0 ' bei =1 werden kein ZwichenMeldungen ausgegeben Modus2 = 0 ' bei =1 werden kein ZwichenMeldungen ausgegeben MaxAnz = 200 LaufWerk = "d:\" LaufWerk = "" If LaufWerk = "" Then LaufWerk = BrowseForFolder( "Verzeichnis auswählen:", 9+16384, 0 ) Text = Text & "Welches Laufwerk soll auf zu lange Dateiennamen (>" Text = Text & MaxAnz & " Zeichen) getestet werden?" ' Pfad erreichbar? ' ------------------------------------------------- If fso.FolderExists( Laufwerk ) Then Else Text = "Für " & LaufWerk & " gilt:" & vbCRLF & vbCRLF & Text & " !" MsgBox vbTab & "= = = F E H L E R = = =" & Laufwerk & vbCRLF & vbCRLF & "ist nicht erreichbar!", , "039 :: " & WScript.ScriptName WScript.Quit End If LogDatei vbCRLF & "++++ " & LaufWerk & " +++++++++++++++" & vbCRLF & "Start" & vbTab & now() & vbCRLF & "Nr." & vbTab & "Länge" & vbTab & "DateiName" Zeit = now() TmpTmp = WScript.ScriptName & "_" & fso.GetBaseName( LaufWerk ) & "_" & ".tmp" ' Prüfen, ob in die Zieldatei noch geschrieben wird ' ------------------------------------------------- if fso.FileExists( TmpTmp )Then Text = fso.GetFile( TmpTmp ).Size wshshell.Popup "Bitte nicht OK drücken!!!" , 3, "Nach 3sek bin ich weg!", vbExclamation, "052 :: " & WScript.ScriptName if not Text = fso.GetFile( TmpTmp ).Size Then MsgBox "Z.Z. wird Laufwerk " & LaufWerk & " noch geprüft.", , "054 :: " & WScript.ScriptName WScript.Quit Else Text = "Laufwerk " & LaufWerk & " wurde bereits geprüft. " Text = Text & "Soll eine neue Liste erstellt werden?" i = MsgBox( Text, 3+32+256, , "059 :: " & WScript.ScriptName ) If i = vbCancel then WScript.Quit End If End If ' MaxAnz festlegen ' ------------------------------------------------- Text = "Dateien mit kompletten Pfad dürfen eine bestimmte Zeichenanzahl nicht übersteigen." & vbCRLF & vbCRLF Text = Text & "Es sollen alle Dateien mit komplettem Pfad aufgelistet werden, deren Zeichenanzahl folgende Zahl übersteigt:" MaxAnz = InputBox (Text, WScript.ScriptName, MaxAnz) If MaxAnz = "" then MsgBox " . . . denn eben nicht!", , "069 :: " & WScript.ScriptName If MaxAnz = "" then WScript.Quit MaxAnz = CInt(MaxAnz) LogDatei vbCRLF & "++++ " & LaufWerk & " +++++++++++++++" & vbCRLF & "Start" & vbTab & now() Zeit = Timer() ' MsgBox LaufWerk, , "075 :: " & WScript.ScriptName RecFolder 0, LaufWerk Text = iLang & vbTab & "Dateien hatten mehr als " & MaxAnz & " Zeichen." & vbCRLF Text = Text & iDatei & vbTab & "Dateien in " & iVerz & " Verzeichnissen auf Laufwerk " & LaufWerk & " wurden überprüft." & vbCRLF Text = Text & vbTab & "Dauer: " & Timer() - Zeit & "s" LogDatei "Nr." & vbTab & "Länge" & vbTab & "DateiName" & vbCRLF & Text LogDatei "Stop " & now() & " - Dauer: " & Timer() - Zeit & "s" MsgBox Text, , "085 :: " & WScript.ScriptName LogDatei "++++ " & LaufWerk & " +++++++++++++++" & vbCRLF WSHShell.run "notepad.exe """ & WScript.ScriptName & ".log""" WScript.Sleep 1500 WSHShell.Sendkeys "^{End}" WScript.Quit ' Autor: (c) Günter Born '*********************************************************** Sub RecFolder (idx, path) ' Rekursive Ordnerbearbeitung (hole Unterordner) Dim oFolders, oSubFolder, oFolder ' Hole Folders-Auflistung ' MsgBox path & vbCRLF & "i: " & i, , "101 :: " & WScript.ScriptName Set oFolders = fso.GetFolder(path) Set Fi = oFolders.Files ' Datei-Listung holen For Each i In Fi ' hole alle Dateien aus Datei-Liste iDatei = iDatei +1 iAnz = iAnz +1 ' If iAnz >= 100 AND Modus2 < 1 Then Modus2 = WSHShell.Popup (iDatei & " Dateien wurden geprüft . . . " & VBCRLF & VBCRLF & "Weiterhin Anzahl der geprüften Dateien anzeigen?", 1, "108 :: " & WScript.Scriptname, 1) if iAnz >= 100 then iAnz = 0 ' if iDatei > 2000 then WScript.Quit Text = path & "\" & oFolders.name & "\" & i.Name if len(Text) > MaxAnz then iLang = iLang +1 Text = iLang & vbTab & len(Text) & vbTab & Text LogDatei Text If Modus1 < 1 Then Modus1 = WSHShell.Popup (Text & VBCRLF & VBCRLF & "Weiterhin jede zu lange Datei anzeigen?", 1, "116 :: " & WScript.Scriptname, 1) End If Next '' Fi.Close Set Fi = Nothing ' Datei schließen Set oSubFolder = oFolders.SubFolders Redim Preserve Txt(idx) ' redim String-Array For Each oFolder in oSubFolder ' alle Ordner iVerz = iVerz +1 ' WSHShell.Popup oFolder & " wird geprüft . . . ", 1, "126 :: " & WScript.Scriptname Txt(idx) = Txt(idx) & path & "\" & oFolder.name & vbCRLF ' Unterordner rekursiv suchen Call RecFolder (idx+1, path & "\" & oFolder.name) Next Set oFolders = Nothing ' Variable freigeben Set oSubFolder = Nothing End Sub ' RecFolder (idx, path) '********************************* Sub LogDatei (LogTxt) '********************************* Dim FileOut, fso Set fso = WScript.CreateObject("Scripting.FileSystemObject") Set FileOut = fso.OpenTextFile(WScript.ScriptName & ".log", 8, true) ' FileOut.WriteLine (vbCRLF & Now() ) FileOut.WriteLine (LogTxt) FileOut.Close Set FileOut = Nothing End Sub ' LogDatei '*** v9.4 *** www.dieseyer.de ******************************* Function BrowseForFolder(strPrompt, intBrowseInfo, vRootFolder) '*********************************************************** ' http://www.codecomments.com/message367170.html ' http://groups.google.de/group/microsoft.public.scripting.vbscript/browse_frm/thread/f083a8d1806e9a68/d835b2a1ec45afec?lnk=st&q=BrowseForFolder+strPrompt+intBrowseInfo+vRootFolder&rnum=1&hl=de#d835b2a1ec45afec ' 'BrowseForFolder dialog. Follows MSDN example closely. Also handles selection of special 'folders (ex Desktop), which do not return a folder3 object as 'normal' folders do. 'Code below does not support all options, only folders. 'To use, copy and paste function into script, 'call as BrowseForFolder(strPrompt, intBrowseInfo, vRootFolder) where root folder is either an 'integer (constants below) or a string with a folder path. 'To use the constants below, they must be in the script header. 'Flags specifying the options for the dialog box. This member can include zero or a combination of the following values. Const BIF_BROWSEFORCOMPUTER = 4096 'Only return computers. If the user selects anything other than a computer, the OK button is grayed. Const BIF_BROWSEFORPRINTER = 8192 'Only allow the selection of printers. If the user selects anything other than a printer, the OK button is grayed. In Microsoft Windows XP, the best practice is to use an XP-style dialog, setting the root of the dialog to the Printers and Faxes folder (CSIDL_PRINTERS). Const BIF_BROWSEINCLUDEFILES = 16384 'Version 4.71. The browse dialog box will display files as well as folders. 'Const BIF_BROWSEINCLUDEURLS = 'Version 5.0. The browse dialog box can display URLs. The BIF_USENEWUI and BIF_BROWSEINCLUDEFILES flags must also be set. If these three flags are not set, the browser dialog box will reject URLs. Even when these flags are set, the browse dialog box will only display URLs if the folder that contains the selected item supports them. When the folder's IShellFolder::GetAttributesOf method is called to request the selected item's attributes, the folder must set the SFGAO_FOLDER attribute flag. Otherwise, the browse dialog box will not display the URL. Const BIF_DONTGOBELOWDOMAIN = 2 'Do not include network folders below the domain level in the dialog box's tree view control. Const BIF_EDITBOX = 16 'Version 4.71. Include an edit control in the browse dialog box that allows the user to type the name of an item. 'Const BIF_NEWDIALOGSTYLE = 'Version 5.0. Use the new user interface. Setting this flag provides the user with a larger dialog box that can be resized. The dialog box has several new capabilities including: drag-and-drop capability within the dialog box, reordering, shortcut menus, new folders, delete, and other shortcut menu commands. To use this flag, you must call OleInitialize or CoInitialize before calling SHBrowseForFolder. Const BIF_NONEWFOLDERBUTTON = 512 'Version 6.0. Do not include the New Folder button in the browse dialog box. 'Const BIF_NOTRANSLATETARGETS = 'Version 6.0. When the selected item is a shortcut, return the PIDL of the shortcut itself rather than its target. Const BIF_RETURNFSANCESTORS = 8 'Only return file system ancestors. An ancestor is a subfolder that is beneath the root folder in the namespace hierarchy. If the user selects an ancestor of the root folder that is not part of the file system, the OK button is grayed. Const BIF_RETURNONLYFSDIRS = 1 'Only return file system directories. If the user selects folders that are not part of the file system, the OK button is grayed. 'Const BIF_SHAREABLE = 'Version 5.0. The browse dialog box can display shareable resources on remote systems. It is intended for applications that want to expose remote shares on a local system. The BIF_NEWDIALOGSTYLE flag must also be set. Const BIF_STATUSTEXT = 4 'Include a status area in the dialog box. The callback function can set the status text by sending messages to the dialog box. This flag is not supported when BIF_NEWDIALOGSTYLE is specified. 'Const BIF_UAHINT = 'Version 6.0. When combined with BIF_NEWDIALOGSTYLE, adds a usage hint to the dialog box in place of the edit box. BIF_EDITBOX overrides this flag. 'Const BIF_USENEWUI = 'Version 5.0. Use the new user interface, including an edit box. This flag is equivalent to BIF_EDITBOX | BIF_NEWDIALOGSTYLE. To use BIF_USENEWUI, you must call OleInitialize or CoInitialize before calling SHBrowseForFolder. Const BIF_VALIDATE = 32 'Version 4.71. If the user types an invalid name into the edit box, the browse dialog box will call the application's BrowseCallbackProc with the BFFM_VALIDATEFAILED message. This flag is ignored if BIF_EDITBOX is not specified. Const ssfALTSTARTUP = 29 'File system directory that corresponds to the user's nonlocalized Startup program group. (value = 29) Const ssfAPPDATA = 26 'Version 4.71. File system directory that serves as a common repository for application-specific data. A typical path is C:\Documents and Settings\username\Application Data. (value = 26) Const ssfBITBUCKET = 10 'Virtual folder containing the objects in the user's Recycle Bin. (value = 15) Const ssfCOMMONALTSTARTUP = 30 'File system directory that corresponds to the nonlocalized Startup program group for all users. Valid only for Microsoft Windows NT systems. (value = 30) Const ssfCOMMONAPPDATA = 35 'Version 5.0. Application data for all users. A typical path is C:\Documents and Settings\All Users\Application Data. (value = 35) Const ssfCOMMONDESKTOPDIR = 25 'File system directory that contains files and folders that appear on the desktop for all users. A typical path is C:\Documents and Settings\All Users\Desktop. Valid only for Windows NT systems. (value = 25) Const ssfCOMMONFAVORITES = 31 'File system directory that serves as a common repository for all users' favorite items. Valid only for Windows NT systems. (value = 31) Const ssfCOMMONPROGRAMS = 23 'File system directory that contains the directories for the common program groups that appear on the Start menu for all users. A typical path is C:\Documents and Settings\All Users\Start Menu\Programs. Valid only for Windows NT systems. (value = 23) Const ssfCOMMONSTARTMENU = 22 'File system directory that contains the programs and folders that appear on the Start menu for all users. A typical path is C:\Documents and Settings\All Users\Start Menu. Valid only for Windows NT systems. (value = 22) Const ssfCOMMONSTARTUP = 24 'File system directory that contains the programs that appear in the Startup folder for all users. A typical path is C:\Documents and Settings\All Users\Start Menu\Programs\Startup. Valid only for Windows NT systems. (value = 24) Const ssfCONTROLS = 3 'Virtual folder containing icons for the Control Panel applications. (value = 3) Const ssfCOOKIES = 33 'File system directory that serves as a common repository for Internet cookies. A typical path is C:\Documents and Settings\username\Cookies. (value = 33) Const ssfDESKTOP = 0 'Microsoft Windows Desktop—virtual folder that is the root of the namespace. (value = 0) Const ssfDESKTOPDIRECTORY = 16 'File system directory used to physically store the file objects that are displayed on the desktop. It is not to be confused with the desktop folder itself, which is a virtual folder. A typical path is C:\Documents and Settings\username\Desktop. (value = 16) Const ssfDRIVES = 17 'My Computer—virtual folder containing everything on the local computer: storage devices, printers, and Control Panel. This folder may also contain mapped network drives. (value = 17) Const ssfFAVORITES = 6 'File system directory that serves as a common repository for the user's favorite items. A typical path is C:\Documents and Settings\username\Favorites. (value = 6) Const ssfFONTS = 20 'Virtual folder containing installed fonts. A typical path is C:\WINNT\Fonts. (value = 20) Const ssfHISTORY = 34 'File system directory that serves as a common repository for Internet history items. (value = 34) Const ssfINTERNETCACHE = 32 'File system directory that serves as a common repository for temporary Internet files. A typical path is C:\Documents and Settings\username\Temporary Internet Files. (value = 32) Const ssfLOCALAPPDATA = 28 'Version 5.0. File system directory that serves as a data repository for local (non-roaming) applications. A typical path is C:\Documents and Settings\username\Local Settings\Application Data. (value = 28) Const ssfMYPICTURES = 39 'My Pictures folder. A typical path is C:\Documents and Settings\username\My Documents\My Pictures. (value = 39) Const ssfNETHOOD = 19 'A file system folder containing the link objects that may exist in the My Network Places virtual folder. It is not the same as ssfNETWORK, which represents the network namespace root. A typical path is C:\Documents and Settings\username\NetHood. (value = 19) Const ssfNETWORK = 21 'Network Neighborhood—virtual folder representing the root of the network namespace hierarchy. (value = 18) Const ssfPERSONAL = 5 'File system directory that serves as a common repository for a user's documents. A typical path is C:\Documents and Settings\username\My Documents. (value = 5) Const ssfPRINTERS = 4 'Virtual folder containing installed printers. (value = 4) Const ssfPRINTHOOD = 18 'File system directory that contains the link objects that may exist in the Printers virtual folder. A typical path is C:\Documents and Settings\username\PrintHood. (value = 27) Const ssfPROFILE = 40 'Version 5.0. User's profile folder. (value = 40) Const ssfPROGRAMFILES = 38 'Version 5.0. Program Files folder. A typical path is C:\Program Files. (value = 38) Const ssfPROGRAMS = 2 'File system directory that contains the user's program groups (which are also file system directories). A typical path is C:\Documents and Settings\username\Start Menu\Programs. (value = 2) Const ssfRECENT = 8 'File system directory that contains the user's most recently used documents. A typical path is C:\Documents and Settings\username\Recent. (value = 8) Const ssfSENDTO = 9 'File system directory that contains Send To menu items. A typical path is C:\Documents and Settings\username\SendTo. (value = 9) Const ssfSTARTMENU = 11 'File system directory containing Start menu items. A typical path is C:\Documents and Settings\username\Start Menu. (value = 11) Const ssfSTARTUP = 7 'File system directory that corresponds to the user's Startup program group. The system starts these programs whenever any user logs onto Windows NT or starts Windows 95. A typical path is C:\Documents and Settings\username\Start Menu\Programs\Startup. (value = 7) Const ssfSYSTEM = 37 'Version 5.0. System folder. A typical path is C:\WINNT\SYSTEM32. (value = 37) Const ssfTEMPLATES = 21 'File system directory that serves as a common repository for document templates. (value = 21) Const ssfWINDOWS = 36 'Version 5.0. Windows directory or SYSROOT. This corresponds to the %windir% or %SYSTEMROOT% environment variables. A typical path is C:\WINNT. (value = 36) Dim oShell Dim oFolder Dim oFolderItem Dim strPath Dim oWSHShell Dim oFSO Dim bSuccess Dim errTst Set oShell = CreateObject("Shell.Application") Set oWSHShell = CreateObject("WScript.Shell") Set oFSO = CreateObject("Scripting.FileSystemObject") Do 'syntax: oFolder = Shell.BrowseForFolder(Hwnd, sTitle, iOptions [,vRootFolder]) Set oFolder = oShell.BrowseForFolder(&H0, strPrompt, intBrowseInfo, vRootFolder) On Error Resume Next 'This seems to get a 'normal' folder object from the folder3 object returned by BrowseForFolder Set oFolderItem = oFolder.Items.Item errTst = Err.Number & " - " & Err.Description On Error GoTo 0 If Len( errTst ) > 4 Then ' MsgBox "Invalid selection; Please try again", , "242 :: " & WScript.ScriptName Else 'If a special folder (ex. desktop) is selected, object is nothing. If (oFolderItem Is Nothing) Then 'This is necessary - seems to convert invalid object reference to a string? strPath = oFolder Set oFolderItem = oFSO.GetFolder(oWSHShell.SpecialFolders(strPath)) End If End If On Error Resume Next If Not oFSO.FolderExists(oFolderItem.Path) Then On Error GoTo 0 MsgBox "Invalid selection; Please try again", , "257 :: " & WScript.ScriptName Else bSuccess = True End If Loop While Not bSuccess BrowseForFolder = oFolderItem.Path End Function ' BrowseForFolder(strPrompt, intBrowseInfo, vRootFolder)