将两个文本文件合并为一个 CSV 文件

发布于 2024-10-11 20:15:06 字数 1418 浏览 2 评论 0原文

我正在使用 Windows 批处理命令来创建文件路径和文件名(不带扩展名)列表以进行处理和存档。我需要创建一个 CSV 文件,其中包含文件路径和文件名。

我能够使用“DIR /ADS /D /S”命令输出带有文件路径的列表,即 filelistA.txt。然后我使用 vbscript (makelistB.vbs) 去除路径和扩展名并将其保存为 filelistB.txt。我需要逐行合并两个文件,将逗号分隔符放在中间,这就是我需要某种 VBscript 的地方。

filelistA.txt 看起来像:
C:\Data\Clients\COLD\AC3060P.txt
C:\Data\Clients\COLD\AC3090P.txt
C:\Data\Clients\COLD\AC3100P.txt
C:\Data\Clients\COLD\AC3150P.txt
C:\Data\Clients\COLD\AC3200P.txt
C:\Data\Clients\COLD\AC3600P.txt
C:\Data\Clients\COLD\AC3652P.txt
C:\Data\Clients\COLD\AC5715P.txt
C:\Data\Clients\COLD\AC5720P.txt
C:\Data\Clients\COLD\AC5725P.txt

filelistB.txt 如下所示:
AC3060P
AC3090P
AC3100P
AC3150P
AC3200P
AC3600P
AC3652P
AC5715P
AC5720P
AC5725P

我想制作FileListCSV.txt,如下所示:
C:\Data\Clients\FWBT\COLD\AC3060P.txt,AC3060P
C:\Data\Clients\FWBT\COLD\AC3090P.txt,AC3090P
C:\Data\Clients\FWBT\COLD\AC3100P.txt,AC3100P
C:\Data\Clients\FWBT\COLD\AC3150P.txt,AC3150P
C:\Data\Clients\FWBT\COLD\AC3200P.txt,AC3200P
C:\Data\Clients\FWBT\COLD\AC3600P.txt,AC3600P
C:\Data\Clients\FWBT\COLD\AC3652P.txt,AC3652P
C:\Data\Clients\FWBT\COLD\AC5715P.txt,AC5715P
C:\Data\Clients\FWBT\COLD\AC5720P.txt,AC5720P
C:\Data\Clients\FWBT\COLD\AC5725P.txt,AC5725P

如果可以一次性完成所有这些操作,我也愿意在 Windows 上使用 SED。不过,我想这应该可以在几分钟内用 VBscript 完成。

I'm working with a windows batch command to create a list of filepaths and filenames (without the ext) for processing and archival. I need to make a CSV file that will contain the path to the file and the filename.

I was able to use the 'DIR /A-D-S /D /S' command to output the list with the file paths, which is filelistA.txt. Then I use a vbscript (makelistB.vbs) to strip the path and extension and save that as filelistB.txt. I need to merge the two files row for row, putting the comma separator in between and that's where I need some sort of VBscript.

filelistA.txt looks like:
C:\Data\Clients\COLD\AC3060P.txt
C:\Data\Clients\COLD\AC3090P.txt
C:\Data\Clients\COLD\AC3100P.txt
C:\Data\Clients\COLD\AC3150P.txt
C:\Data\Clients\COLD\AC3200P.txt
C:\Data\Clients\COLD\AC3600P.txt
C:\Data\Clients\COLD\AC3652P.txt
C:\Data\Clients\COLD\AC5715P.txt
C:\Data\Clients\COLD\AC5720P.txt
C:\Data\Clients\COLD\AC5725P.txt

filelistB.txt looks like:
AC3060P
AC3090P
AC3100P
AC3150P
AC3200P
AC3600P
AC3652P
AC5715P
AC5720P
AC5725P

I want to make FileListCSV.txt, that looks like this:
C:\Data\Clients\FWBT\COLD\AC3060P.txt,AC3060P
C:\Data\Clients\FWBT\COLD\AC3090P.txt,AC3090P
C:\Data\Clients\FWBT\COLD\AC3100P.txt,AC3100P
C:\Data\Clients\FWBT\COLD\AC3150P.txt,AC3150P
C:\Data\Clients\FWBT\COLD\AC3200P.txt,AC3200P
C:\Data\Clients\FWBT\COLD\AC3600P.txt,AC3600P
C:\Data\Clients\FWBT\COLD\AC3652P.txt,AC3652P
C:\Data\Clients\FWBT\COLD\AC5715P.txt,AC5715P
C:\Data\Clients\FWBT\COLD\AC5720P.txt,AC5720P
C:\Data\Clients\FWBT\COLD\AC5725P.txt,AC5725P

I'm also open to using SED for windows if that can do all of this in one shot. However, I would imagine this should be something that can be whipped up in VBscript in a few minutes.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

空名 2024-10-18 20:15:06

此 Windows 批处理文件将执行您想要的操作,而不需要中间文件。

@ECHO OFF

FOR %%i IN (*.txt) DO ECHO %%~fi,%%~ni

您可以通过像这样重定向输出来将此批处理的输出放入文本文件中:

MyBatch.cmd>>Output.txt

This Windows batch file will do what you want without the need for the intermediate files.

@ECHO OFF

FOR %%i IN (*.txt) DO ECHO %%~fi,%%~ni

You can get the output of this batch into a text file by redirecting the output like this:

MyBatch.cmd>>Output.txt
屋顶上的小猫咪 2024-10-18 20:15:06

这可能是 SQLite shell 的工作。

C:\Temp> sqlite3.exe
create table paths(path text);
create table filenames(fname text);
.import fileListA.txt paths
.import fileListB.txt filenames
.separator ,
.output FileListCSV.txt
select * from paths p join filenames f on f.rowid = p.rowid;
.q

SQLite shell 是一个单一的可执行文件,它将以文件的形式创建一个持久的 SQLite 数据库,或者在内存中创建一个数据库(当像这里一样,在命令行中没有任何参数时)。

This could be a job for the SQLite shell.

C:\Temp> sqlite3.exe
create table paths(path text);
create table filenames(fname text);
.import fileListA.txt paths
.import fileListB.txt filenames
.separator ,
.output FileListCSV.txt
select * from paths p join filenames f on f.rowid = p.rowid;
.q

The SQLite shell is a single executable that will either create a persistent SQLite database in the form of a file, or create a database in memory (when, like here, without any argument in the command line).

时光是把杀猪刀 2024-10-18 20:15:06

这可以在 EasyMorph 中使用“追加列”模式下的追加转换非常快速地完成。

This can be done pretty fast in EasyMorph using Append transformation in "Append columns" mode.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文