当前位置: 动力学知识库 > 问答 > 编程问答 >

file - How to pass parameters to built in Windows commands via AutoHotKey?

问题描述:

I'm trying to create a simple file merge tool to combine split log file in to a text file.

FileSelectFolder, folder, \\Myserver\Data\

InputBox, filename, Save File,Please type the name you will call the merged file.`n The file will be saved in the folder "merged" of the same root directory as its "part files" are located., , , , , , , ,merged_file.txt

if errorlevel = 1

exitApp

IfExist, %folder%\merged\%filename%

MsgBox, 4, File Overwrite -or- Append?, The file already exists. Do you want to append to this file? `nNote: If you select "No" the existing file will be replaced during this process.

ifmsgbox, no

FileDelete %folder%\merged\%filename%

FileCreateDir, %folder%\merged

IfExist %folder%\merged\%filename%_file_list.txt

FileDelete %folder%\merged\%filename%_file_list.txt

Runwait, %COMSPEC% /c copy /k %folder%\*.log %folder%\merged\%filename%

ExitApp

I did not want to use AHK fileread and fileappend as log file are quite big ~40mb.

The above code does not yield any errors but does not produce any file either.

I tried adding " to the parameters with no success.

网友答案:

It's really easy actually:

Loop, Read, C:\FileToReadFrom.txt, C:\FileToAddTo.txt
    FileAppend, `r`n%A_LoopReadLine% 

This way you only load one line at a time into the RAM.

If you want to know more:
Loop, Read file contents
FileAppend

网友答案:

Okay one more shot here!

As it turns out you do need to quote your Path in command string for use with COMSPEC.

I also correctly stated earlier that there is no /K switch or option for the Copy command. There is Compsec switch /K which Keeps the Terminal Open and a /c which means Close Terminal.

Also your syntax is wrong with Copy. In order to Concatenate a file with Copy you need to do something like this:

Copy mergedfile.txt+file2merge.txt newmergedfile.txt

But I suggest you use Type to Concatenate a text file instead:

RunWait, %COMSPEC% /c type "%folder%\*.log" >> "%folder%\merged\%filename%"
分享给朋友:
您可能感兴趣的文章:
随机阅读: