批处理文件可以告诉程序将文件另存为吗?(如果有,如何) [英] Can a Batch File Tell a program to save a file as? (If so how)

查看:33
本文介绍了批处理文件可以告诉程序将文件另存为吗?(如果有,如何)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试自动执行工作文件传输过程,但我不确定如何让程序保存文件.

I am currently trying to automate a file transfer process for work and I am not sure how to have a program save a file.

目前我已经创建了一个工作批处理来将日志文件从创建点移动到正确的文件夹并重命名它以包含日期.然后使用 start 函数打开该文件.到目前为止,所有这些都有效.

Currently I have created a working batch to move a log file from the point of creation to the correct folder and rename it to include the date. Then use the start function to open that file. All of this works so far.

现在我需要打开的那个文件文件>另存为>保存

Now I need that file which was opened to go File>save as>save

它不需要更改名称.打开它的程序只保存为 CVS,这是我的最终目标.

It doesn't need the name changed. The program that opens it only saves as CVS and that is my ultimate goal.

除非有人知道将日志文件更改为 CSV 文件的更简单方法,否则我也愿意接受该选项.在批处理文件中.

Unless someone knows an easier way to change a log file to a CSV file, I am open to that option as well. In a batch file.

Windows 7 电脑

Windows 7 computer

编辑 1*

使用 ren 命令将其重命名为 csv 会使数据在 Excel 中打开时变成垃圾.通过该程序使日志成为 csv,使数据以正确的格式显示.我需要知道如何告诉程序另存为.由于没有快捷方式,我想我需要一种方法来告诉它按下:altF 向下(箭头键)输入回车

Renaming it to a csv using the ren command turns the data to garbage when it opens in excel. Going through the program to make the log a csv makes the data appear in the correct format. I need to know how to tell the program to save as. Since there is no shortcut I think I need a way to tell it to push: altF down down (arrow keys) enter enter

我意识到像 autoit 这样的程序能够执行该功能,但由于公司计算机的限制,它们不会成为一种选择.

I realize that programs like autoit are capable of preforming the function but they are not going to be an option due to restraints with company computers.

进一步的研究使我看到了这篇文章:使用批处理文件按键盘键但是我无法找到一种方法来使这个想法适用于我的案例.也许它会让某人离开,尽管更了解它.

Further Research lead me to this post: Press Keyboard keys using a batch file But I am unable to find a way to make this idea work for my case. Maybe it will give someone to go off of though that understands it more.

编辑 2*这看起来可能会变得丑陋,但如果有人也理解这一点,它可能对我需要的东西非常有用.https://msdn.microsoft.com/en-us/library/8c6yea83.aspx

EDIT 2* This looks like it might get ugly but if anyone understands this as well it could prove very useful for what I need. https://msdn.microsoft.com/en-us/library/8c6yea83.aspx

编辑 3*抱歉问了这么宽泛的问题,但感谢您的帮助.

EDIT 3* Sorry for the broad question but thanks for your assistance.

目前的 BAT 非常简单:

The BAT so far is pretty simple:

Move/-y "C:UsersxxxDesktopASI Test FolderStation 5Station 5 LogStation 5 Log.log" "O:LABASILogs by DateWeek 2015-4-13"

Move /-y "C:UsersxxxDesktopASI Test FolderStation 5Station 5 LogStation 5 Log.log" "O:LABASILogs by DateWeek 2015-4-13"

ren "O:LABASILogs by DateWeek 2015-4-13Station 5 Log.log" "Station 5 Log %date:~4,2%-%date:~7,2%-%date:~10,4%.log"

ren "O:LABASILogs by DateWeek 2015-4-13Station 5 Log.log" "Station 5 Log %date:~4,2%-%date:~7,2%-%date:~10,4%.log"

start "" "C:UsersxxxDesktopASI Test FolderStation 5Station 5 LogStation 5 log.log

start "" "C:UsersxxxDesktopASI Test FolderStation 5Station 5 LogStation 5 log.log

暂停

我正在尝试将密钥发送到 RSView 以保存程序.这将使它成为一个可以作为 EXCEL 文档打开的 CSV 文件,我已经在其中创建了一个宏,可以将该数据转换为更易读/图表格式.

I am trying to send keys to RSView to have it save the program. This will make it a CSV that can be opened as an EXCEL doc where I already created a macro that converts that data into a more readable/chartable format.

如果我们可以将其保存为 CSV,我可以再次使用 start 命令在 Excel 中打开它,然后运行宏.

If We can save this as a CSV I can use the start command again to open it in excel then run the macro.

推荐答案

经过大量研究,我终于解决了我的问题.

After much research I was able to solve my problem.

对我原来的问题的简单回答:批处理文件可以告诉程序另存为吗?是/有点.

The simple answer to my original question: Can a Batch file tell a program to save as? Is yes/sort of.

虽然批处理不能直接将键命令发送到传统意义上的另一个程序,但有一些变通方法.如果处理得当,可以在同一个批处理文件中包含多种脚本语言,您可以在批处理中使用 java 或 vbs 语言将密钥发送到程序.为了在您需要时选择活动窗口进行保存,然后发送将获得另存为功能的键盘命令.示例:Alt+F Down Down Enter Enter.这会告诉程序打开文件菜单,向下选择适当的次数以选择另存为,然后按 Enter 告诉它打开另存为菜单,然后再次输入将告诉它保存.

While a batch cannot directly send key commands to another program in the traditional sense there are work arounds. It is possible to include multiple scripting languages in the same batch file if done appropriately you can use either java or vbs language in your batch to send keys to a program. In order to save as you need to select active window, then send key commands that would get to the save as function. Example: Alt+F Down Down Enter Enter. That would tell the program to open the file menu, go down the appropriate number of times to select save as then hit enter to tell it to open the save as menu then enter again would tell it to save.

如果你不擅长脚本部分,比如我.然后创建一个批处理文件来执行所有移动/重命名/打开并使用 wsf 文件发送密钥可能会更容易.wsf 文件与批处理文件非常相似,但它是用 java 或 vbs 编写的.它比将 vbs 和普通脚本添加到批处理中要简单.所以这就是我如何解决我的问题.三个文件:一批告诉 wsf 文件在我需要发送密钥时打开我需要将密钥发送到程序的两个不同时间的两个 wsf 文件.(每个打开的程序需要一个 wsf)

If you are not very good with the scripting part, like me. Then it will probably be easier to create a batch file that does all the moving/renaming/opening and use wsf files to send keys. A wsf file is very similar to a batch file but it is written in java or vbs. It is less complicated than adding in both vbs and normal script to the batch. So here is how I solved my problem. Three Files: One Batch that told wsf files to open when I needed to send keys Two wsf files for the two separate times I needed to send keys to a program. (You need one wsf per program you open)

这里是每个文件的代码:

Here are the codes for each file:

批次:

    Move /-y "C:UsersxxxxDesktopASI Test FolderStation 5Station 5 LogStation 5 Log.log" "O:LABASILogs by DateWeek 2015-4-13"
    timeout /t 1
    ren "O:LABASILogs by DateWeek 2015-4-13Station 5 Log.log" "Station 5 Log %date:~4,2%-%date:~7,2%-%date:~10,4%.log"
    timeout /t 1

    start "" "O:LABASILogs by DateWeek 2015-4-13Station 5 log %date:~4,2%-%date:~7,2%-%date:~10,4%.log
    timeout /t 1

    start "" "C:UsersxxxxDesktopWorking BATSSend Keys test.wsf"
    timeout /t 5

    start "" "O:LABASILogs by DateWeek 2015-4-13Station 5 Log %date:~4,2%-%date:~7,2%-%date:~10,4%.csv
    timeout /t 4

    start "" "C:UsersxxxxDesktopWorking BATSExcel Macro.wsf
    pause

非常基本的东西.超时功能用于解决打开文件时的延迟.虽然没有必要每次都移动/重命名,但有时在下一次完成时动作不会完成.所以这确保它每次都有效.WSF(发送密钥测试):

Pretty basic stuff. Timeout function was used to account for the delay when opening files. While it wasn't necessary for moving/renaming every time, sometimes actions wouldn't be complete when the next one went through. So this made sure it worked every time. WSF (Send Keys test):

    <package>
    <job id="vbs">
    <script language="VBScript">
 set WshShell = WScript.CreateObject("WScript.Shell")
 WshShell.AppActivate "RSView Enterprise File Viewer"
     WScript.Sleep 100
     WshShell.SendKeys "%f"
     WScript.Sleep 500
     WshShell.SendKeys "{Down}"
     WScript.Sleep 500
     WshShell.SendKeys "{Down}"
     WScript.Sleep 500
 WshShell.SendKeys "{Enter}"
     WScript.Sleep 500
     WshShell.SendKeys "{Enter}"
     WScript.Sleep 500
 </script>
     </job>
     </package>

应用活动窗口非常重要.它确保将密钥发送到正确的窗口.这是用于让 RSView 将日志文件保存为 CSV 的文件.

The app active window is very important. It makes sure the keys are sent to the correct window. This is the file used to have RSView save the log file as a CSV.

WSF2(Excel 宏):

WSF2 (Excel Macro):

    <package>
    <job id="vbs">
    <script language="VBScript">
 set WshShell = WScript.CreateObject("WScript.Shell")
 WshShell.AppActivate "Excel"
     WScript.Sleep 100
     WshShell.SendKeys "^u"
 </script>
     </job>
     </package>

希望这能帮助任何遇到类似问题的人.对我来说,这里的关键是弄清楚如何将密钥发送到程序.

Hope this helps anyone who runs into a similar problem as I did. The key here for me was figuring out how to send keys to a program.

这篇关于批处理文件可以告诉程序将文件另存为吗?(如果有,如何)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆