一个批处理文件可以给程序将文件保存为? (如果是的话如何) [英] Can a Batch File Tell a program to save a file as? (If so how)

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

问题描述

我目前正在实现自动化工作的文件传输过程中,我不知道如何有一个程序保存文件。

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.

目前我已经创建了一个工作一批从创建点的日志文件移动到正确的文件夹并将其重命名为包括日期。然后使用启动功能,打开该文件。所有这一切工作至今。

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 down下来(箭头键)进入输入

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的程序能够preforming功能,但他们不会是一个选项由于与公司电脑的限制。

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.

进一步研究使我这个帖子:
使用批处理文件 preSS键盘键
但我无法找到一种方法,使我的情况下,这个想法的工作。也许它会给人走下车的,虽然能够理解它了。

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

编辑3 *
对不起,广泛的问题,但感谢您的帮助。

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

该BAT到目前为止pretty简单:

The BAT so far is pretty simple:

移动/ -yC:\\用户\\ XXX \\桌面\\ ASI测试文件夹\\站5 \\站5登录\\站5 Log.log的O:\\ LAB \\ ASI \\ Logs中由2015-4日期\\周-13

Move /-y "C:\Users\xxx\Desktop\ASI Test Folder\Station 5\Station 5 Log\Station 5 Log.log" "O:\LAB\ASI\Logs by Date\Week 2015-4-13"

仁的O:\\ LAB \\ ASI \\ Logs中按日期\\情节中字周\\站5 Log.log,站5登录%日期:〜4.2% - %日期:7,2〜% - %日期:10,4〜.LOG%

ren "O:\LAB\ASI\Logs by Date\Week 2015-4-13\Station 5 Log.log" "Station 5 Log %date:~4,2%-%date:~7,2%-%date:~10,4%.log"

启动C:\\用户\\ XXX \\桌面\\ ASI测试文件夹\\站5 \\站5登录\\站5 log.log

start "" "C:\Users\xxx\Desktop\ASI Test Folder\Station 5\Station 5 Log\Station 5 log.log

暂停

我试图发送键的RSView把它保存程序。这将使它能够在那里我已经创建的,其将数据转换为更可读/ chartable格式。

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羽绒服回车进入。这将告诉程序打开文件菜单,下井的次数适当数量的选择保存为按下回车键来告诉它打开另存为菜单,然后再输入会告诉它来保存。

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)

下面是codeS为每个文件:

Here are the codes for each file:

批次:

    Move /-y "C:\Users\xxxx\Desktop\ASI Test Folder\Station 5\Station 5 Log\Station 5 Log.log" "O:\LAB\ASI\Logs by Date\Week 2015-4-13"
    timeout /t 1
    ren "O:\LAB\ASI\Logs by Date\Week 2015-4-13\Station 5 Log.log" "Station 5 Log %date:~4,2%-%date:~7,2%-%date:~10,4%.log"
    timeout /t 1

    start "" "O:\LAB\ASI\Logs by Date\Week 2015-4-13\Station 5 log %date:~4,2%-%date:~7,2%-%date:~10,4%.log
    timeout /t 1

    start "" "C:\Users\xxxx\Desktop\Working BATS\Send Keys test.wsf"
    timeout /t 5

    start "" "O:\LAB\ASI\Logs by Date\Week 2015-4-13\Station 5 Log %date:~4,2%-%date:~7,2%-%date:~10,4%.csv
    timeout /t 4

    start "" "C:\Users\xxxx\Desktop\Working BATS\Excel Macro.wsf
    pause

pretty基本的东西。超时功能被用来打开文件时考虑到的延迟。同时,没有必要为移动/重命名每一次,有时操作不会当下一个所经历完整的。因此,这确定它的工作每次。
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天全站免登陆