Merge 2 text files to one in every subfolder and save them in the same Folder as Date and File named csv file.

▼魔方 西西 提交于 2019-12-11 18:34:12

问题


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:


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.



来源:https://stackoverflow.com/questions/52112646/merge-2-text-files-to-one-in-every-subfolder-and-save-them-in-the-same-folder-as

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!