最近大半年刷了160多天的题,每次刷的时候都要新建一个VS文件,所以文件内存太大了,又舍不得删,就用ai整了一个脚本,可将当前路径下的所有文件里的.cpp和.h文件储存到相应名字的txt文件里,若文件夹下还有文件则会将其保存在对应的文件夹下,并最终将所有文件保存在一个文件夹里。(中文会乱码,可能是保存格式的问题,懒得改。注意此脚本统计的是当前路径下的所有文件里的cpp和.h所以最好不要有环境什么的.可能还有少许bug)以下是效果图


代码为
Set fso = CreateObject("Scripting.FileSystemObject")
 Set folder = fso.GetFolder(".")
' Create a new folder in the current directory to store the txt files
 outputRootFolder = fso.BuildPath(folder.Path, "txt_files")
 If Not fso.FolderExists(outputRootFolder) Then
     fso.CreateFolder(outputRootFolder)
 End If
ProcessFolder folder
Sub ProcessFolder(folder)
     For Each subFolder In folder.SubFolders
         ProcessFolder subFolder
     Next
    For Each file In folder.Files
         If LCase(fso.GetExtensionName(file)) = "cpp" Or LCase(fso.GetExtensionName(file)) = "h" Then
             SaveFileContentToTxt file, folder
         End If
     Next
 End Sub
Sub SaveFileContentToTxt(file, folder)
     Dim inputFile, outputFile, fileContent, outputFolder, outputFileName, parentFolderName
     Set inputFile = fso.OpenTextFile(file, 1)
     
     ' Check if the file is empty
     If inputFile.AtEndOfStream Then
         inputFile.Close
         Exit Sub
     End If
     
     fileContent = inputFile.ReadAll
     inputFile.Close
    parentFolderName = fso.GetBaseName(folder.Path)
     outputFolder = fso.BuildPath(outputRootFolder, parentFolderName & "txt")
    If Not fso.FolderExists(outputFolder) Then
         fso.CreateFolder(outputFolder)
     End If
    outputFileName = fso.BuildPath(outputFolder, fso.GetBaseName(file) & ".txt")
     Set outputFile = fso.CreateTextFile(outputFileName, True)
     outputFile.Write fileContent
     outputFile.Close
 End Sub
 将其复制进一个新建的txt文件,在将后缀名改为.vbs再双击即可