I need to know that files have more then one consecutives empty lines in all files of one folder and subfolders.
I use \n\n and appears : Cannot search files for a regular expression including '\n'
Best regards
find consecutives empty lines in all files
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
Here is a VBscript to do that.It looks for 3 consecutive Carriage Return/LineFeed characters.
Code: Select all
'=======================================================================
'- WINDOWS VBSCRIPT
'- FIND TEXT FILE WITH 2 CONSECUTIVE EMPTY LINES - option to open it
'- Copy/past this text to a text file. Save the file with extension .vbs. Double click it to run.
'- Brian Baulsom April 2010
'=======================================================================
Dim FSO ' FileSystemObject
Dim WSH ' Shell
Dim RootFolder
Dim UserCancelled
Dim rsp
'----------------------------------------------------------------------------------------------------------------------------------------------------------------
main
'=======================================================================
'- MAIN ROUTINE
'=======================================================================
Sub Main()
'------------------------------------------------------------------------------------------------
'- ROOT FOLDER TO START SEARCHING FROM ********************************
Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
Set RootFolder = FSO.GetFolder("F:\Test\") ' ** CHANGE AS NECESSARY
'------------------------------------------------------------------------------------------------
Set WSH =WScript.CreateObject("WScript.Shell")
UserCancelled=False
'------------------------------------------------------------------------------------------------
GetFiles RootFolder ' check files in the root Folder first
If UserCancelled=true then exit Sub
GetFolders RootFolder
End Sub
'=======================================================================
'- SUBROUTINE : GET FOLDERS
'=======================================================================
Sub GetFolders(basefolder)
Dim MainFolder
Dim SubFolders
Dim Folder
Dim FolderName
'------------------------------------------------------------------------------------------------
set MainFolder=basefolder
Set SubFolders = MainFolder.SubFolders
'------------------------------------------------------------------------------------------------
'- LOOP FOLDERS
For Each Folder In SubFolders
FolderName = Folder.Name
'----------------------------------------------------------------------------------------
GetFiles Folder ' get files in the folder
GetFolders Folder ' get folders in the folder
'---------------------------------------------------------------------------------------
'- check If folder message cancelled (=abort)
If UserCancelled=true then exit Sub
'---------------------------------------------------------------------------------------
Next
End Sub
'=========== end of Sub ==================================================
'====================================================================
'- SUBROUTINE : GET FILES IN Folder
'====================================================================
Sub GetFiles(myfolder)
Dim MyFolderName
Dim MyFiles
Dim MyFile
Dim MyFileName
Dim MyFileContents
Dim MyFileText
Dim CheckString
Const ForReading=1, TristateDefault=-2
Dim fn ' full path & file name
'-------------------------------------------------------------------------------------------
MyFolderName=myfolder.path
Set MyFiles = MyFolder.Files
CheckString=vbCrLf &vbCrLf &vbCrLf ' test for 3 consecutive end of lines
'------------------------------------------------------------------------------------------
'- LOOP THROUGH THE FILES IN THE Folder
For Each MyFile In MyFiles
MyFileName=MyFile.name
'----------------------------------------------------------------------------------
If right(MyFileName,3)="txt" then
'--------------------------------------------------------------------------
'- Read the text file
Set MyFileContents = MyFile.OpenAsTextStream(ForReading,TrisateDefault)
MyFileText=MyFileContents.ReadAll
'-------------------------------------------------------------------------
'- FILE FOUND : Message Box
If Instr(1,MyFileText,checkstring,1)<>0 then
rsp= msgbox("This file contains 2 consecutive empty lines." &vbcr _
&"Do you wish to open it ?" &vbCr _
&"Folder : " &MyFolderName &vbcr _
&"File : " &MyFileName,vbYesNoCancel," FOUND FILE")
'---------------------------------------------------------------
If rsp=vbCancel then
UserCancelled=true
Exit Sub
'----------------------------------------------------------------
ElseIf rsp=vbYes then
fn= MyFolderName &"\" &MyFileName
WSH.Run "%windir%\notepad " & fn
End If
'----------------------------------------------------------------
End If
'---------------------------------------------------------------------------
MyFileContents.Close ' close the text file
End If
'-----------------------------------------------------------------------------------
next
'-------------------------------------------------------------------------------------------
End Sub
'=========== end of Sub ==================================================