如何将批处理文件的内容传输到记事本或excelsheet中?

如何将批处理文件的内容传输到记事本或excelsheet中?

我有一份批处理文件列表。我想将所有文件的所有内容传输到单个记事本或 Excel 表中,制作一个列表。

答案1

我将在 powershell 中执行此操作。假设所有批处理文件都放在 1 个文件夹中。

----- 将此行以下的所有文本复制并粘贴到 1 个脚本文件中 -----

#### Determine the location of all batchfiles
$BatchesFolder = "E:\Batches"

#### Determine the file for all collected data
$resultfile = "E:\Data\results.txt"

#### Read all files in batch folder
$batchfiles = (Get-ChildItem $BatchesFolder).fullname

#### Read each file and store data in result file
Foreach ($file in $batchfiles)
    {
    "--- Content of file $file ---" | Out-File -FilePath $resultfile -Append
    get-content $file | Out-File -FilePath $resultfile -Append
    }

答案2

使用cmd.exe

type C:\PathToBatchFiles\* > C:\PathToOutputFolder\OutputFile.txt

PathToBatchFiles 目录下每个文件的内容将被打印到 OutputFile.txt 中,不带任何文件名分隔符。

答案3

这是在 Excel 中使用虚拟专用网络

我有一些。蝙蝠文件夹中的文件名为钟楼

在此处输入图片描述

运行这个虚拟专用网络宏:

Sub BatLister()
    Dim s1 As Worksheet, s2 As Worksheet
    Dim WhereToLook As String, FileName As String
    Dim fPath As String, FileSpec As String
    Dim L As Long, i As Long, j As Long

    Set s1 = Sheets("bat dir")
    Set s2 = Sheets("bat list")
    s1.Cells.Clear
    s2.Cells.Clear
    WhereToLook = "C:\Users\garys\Documents\Belfry\*.bat"
    fPath = "C:\Users\garys\Documents\Belfry\"

    L = 1
    FileName = Dir(WhereToLook)
    FileSpec = fPath & FileName
    Do Until FileName = ""
        s1.Cells(L, 1) = FileSpec
        L = L + 1
        FileName = Dir()
        FileSpec = fPath & FileName
    Loop

    j = 1
    For i = 1 To L - 1
        FileSpec = s1.Cells(i, 1).Value
        s2.Cells(j, 1) = FileSpec
        j = j + 1
        Close #2
        Open FileSpec For Input As #2
        Do While Not EOF(2)
            Line Input #2, TextLine
            s2.Cells(j, 2) = TextLine
            j = j + 1
        Loop
    Next i
    Close #2
End Sub

将列出所有。蝙蝠文件夹中的文件。

列中的文件名A以及列中的文件内容

在此处输入图片描述

相关内容