.bat Find and Rename
I have outputted some text files all in the same directory. Each .txt file has within a group number, this number always starts with RXC and can go upwards of 5 characters afterwards, giving us RXCXXXXX i开发者_JAVA技巧 need the script to find this RXC number and rename the file to its corresponding group number, then do the same for all files in the same directory.
Thanks in advance, Joe
using System.IO;
foreach(var file in Directory.GetFiles("."))
{
var content = File.ReadAllText(file);
var startIndex = content.IndexOf("RXC");
var id = content.Substring(startIndex, 8);
File.Move(file, id);
}
Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder="c:\test"
Set objFolder = objFS.GetFolder(strFolder)
For Each strFile In objFolder.Files
If objFS.GetExtensionName(strFile) = "txt" Then
strFileName = strFile.Name
Set objFile = objFS.OpenTextFile(strFileName)
Do Until objFile.AtEndOfStream
strLine=objFile.ReadLine
If InStr(strLine,"RXC" ) > 0 Then
number=Mid(strLine,4)
objFile.Close
strFile.Name = Trim(number)&".txt"
Exit Do
End If
Loop
End If
Next
精彩评论