Merge 2 text files to one in every subfolder and s

2019-08-21 03:54发布

I wanted to merge in every Folder 2 existing txt files into one and save it in the same Folder as .csv. The Name of new File have to be Date and Time.

for /r C:\Users\Juan\Desktop\Konturograph\ %%G in (*.txt) do (
xcopy "%%G" "G%% %date% %time:~0,2%-%time:~3,2%-%time:~6,2%".csv
echo %%G
)
pause

I am trying with this but that just create 2 .cvs. I have no idea from Batch and I think I am very far from my Target, could you help me please?

Thank you very much in advance.

Grüße Juan

1条回答
该账号已被封号
2楼-- · 2019-08-21 04:36

There is no such token as G%%. If you want to copy the file from a .txt extension to .csv use %%~nG for name of file, excluding extension.

@echo off
for /r "C:\Users\Juan\Desktop\Konturograph\" %%G in (*.txt) do (
    xcopy "%%G" "%%~nG %date% %time:~0,2%-%time:~3,2%-%time:~6,2%.csv"
    echo "%%G"
)
pause

However, seeing that you want to merge files, that will not work. try something like:

@echo off
for /r "C:\Users\Juan\Desktop\Konturograph\" %%G in (*.txt) do (
    type %%G >> OUTPUT.csv
    echo "%%G"
)
pause

You will not be able to use time in the timestamp as time changes during each loop, it will change the filename.

查看更多
登录 后发表回答