bat script to find file name in a file
Moderator: DosItHelp
-
- Posts: 15
- Joined: 14 Jun 2010 06:50
bat script to find file name in a file
Hello All,
It's been a while since my last question. I have 1 now so here it goes:
I want to write a bat file that will loop through a folder (and also sub-folders in it) and read each file. File can be of any type..mostly ASP and html. It should read all lines and find anything which ends with .asp or .html.
e.g.: I have 1 html file and within it i am calling 2 html files in anchor tag (<a>2.html</a><a>3.html</a>), so the bat file should list down 2.html and 3.html.
Also,
Should I use bat script to code this at all??
Let me know if anything is not clear...
It's been a while since my last question. I have 1 now so here it goes:
I want to write a bat file that will loop through a folder (and also sub-folders in it) and read each file. File can be of any type..mostly ASP and html. It should read all lines and find anything which ends with .asp or .html.
e.g.: I have 1 html file and within it i am calling 2 html files in anchor tag (<a>2.html</a><a>3.html</a>), so the bat file should list down 2.html and 3.html.
Also,
Should I use bat script to code this at all??
Let me know if anything is not clear...
Re: bat script to find file name in a file
IMO never a good idea to parse html source text by batch.
When I'm at home I will try to write it in VBScript.
Is it a rule that the file names are separated by > and < ?
Regards
aGerman
When I'm at home I will try to write it in VBScript.
Is it a rule that the file names are separated by > and < ?
Regards
aGerman
-
- Posts: 319
- Joined: 12 May 2006 01:13
Re: bat script to find file name in a file
aGerman wrote:IMO never a good idea to parse html source text by batch.
When I'm at home I will try to write it in VBScript.
Is it a rule that the file names are separated by > and < ?
Regards
aGerman
even vbscript is not the correct tool to parse html. HTML parsers is the way to go.
Re: bat script to find file name in a file
Of course, but I thought about splitting the entire file content to get an array where we could find the file names by looping over the elements.
But first I will wait for response, what exactly I could use as separator.
Regards
aGerman
But first I will wait for response, what exactly I could use as separator.
Regards
aGerman
-
- Posts: 319
- Joined: 12 May 2006 01:13
Re: bat script to find file name in a file
if its between anchor tags then the most probable separator to use is </a> (case insensitive)
-
- Posts: 15
- Joined: 14 Jun 2010 06:50
Re: bat script to find file name in a file
ok...we generally include file names in anchor tags...but there are other ways of doing it also apart from anchor tags..like <# include...>
Cant we search for .asp in a line and then take out the filename?
Cant we search for .asp in a line and then take out the filename?
-
- Posts: 319
- Joined: 12 May 2006 01:13
Re: bat script to find file name in a file
so why don't you show a sample of your file? I can't answer you based on what you ask since we didn't see your input file. Next time when you ask questions, provide enough input and clearly describe the output you want so that we don't waste each other's time posting back and forth.
Re: bat script to find file name in a file
agrawal.meet wrote:Cant we search for .asp in a line and then take out the filename?
No, because I don't know how to separate it from the source text.
You could return the entire line, but as you should know it's possible that there are more than one file name in a line. Further more it is possible to write the whole source text of a HTML file to a single line. Probably too large to process it by batch.
Regards
aGerman
-
- Posts: 15
- Joined: 14 Jun 2010 06:50
Re: bat script to find file name in a file
my bad...here is the code from sample file called a.asp
How should I go ahead. I want output as...check_site_avail.asp, CTranslate.asp, PerfLogCookies.asp
Also,
If a single line has reference to 2 or more asp files..they should be treated as same.
Code: Select all
<html>
<!-- #include virtual="/CAT/inc\check_site_avail.asp" -->
<!-- #include virtual="/CAT/inc\CTranslate.asp" -->
<!-- #include virtual="/CAT/PerfTst/PerfLogCookies.asp"-->
</html>
How should I go ahead. I want output as...check_site_avail.asp, CTranslate.asp, PerfLogCookies.asp
Also,
If a single line has reference to 2 or more asp files..they should be treated as same.
Re: bat script to find file name in a file
Sorry guys, I'm currently in China and have less time.
@agrawal.meet
This small VBScript would probably work for files like your example
Regards
aGerman
@agrawal.meet
This small VBScript would probably work for files like your example
Code: Select all
' change it:
sRootFolder = "C:\whereever"
Sub ProcFile(sFileName)
Set oFile = oFS.OpenTextFile(sFileName)
sArrContent = Split(oFile.ReadAll, """")
oFile.Close
For Each sElement In sArrContent
If LCase(Right(sElement, 4)) = ".asp" Then
Redim Preserve sArrFoundNames(i)
sPart = Right(sElement, Len(sElement) - InStrRev(sElement, "\"))
sArrFoundNames(i) = Right(sPart, Len(sPart) - InStrRev(sPart, "/"))
i = i + 1
End If
Next
End Sub
Sub procFolder(sFolderName)
Set oFolder = oFS.GetFolder(sFolderName)
Set colFiles = oFolder.Files
For Each oFileItem In colFiles
If LCase(oFS.GetExtensionName(oFileItem)) = "html" Then
ProcFile oFS.GetParentFolderName(oFileItem) & "\" & oFileItem.Name
End If
Next
Set colFolders = oFolder.SubFolders
For Each oFolderItem In colFolders
procFolder oFS.GetAbsolutePathName(oFolderItem)
Next
End Sub
Dim sArrFoundNames(), i
Set oFS = CreateObject("Scripting.FileSystemObject")
procFolder sRootFolder
Set oOutFile = oFS.CreateTextFile("output.txt", True)
For Each sItem In sArrFoundNames
oOutFile.WriteLine(sItem)
Next
oOutFile.Close
WScript.Echo "ready"
Regards
aGerman
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: bat script to find file name in a file
What's happening in China, aGerman?