如何在 DOS 中动态指定文件?
我正在尝试在 .net 中使用 c# 运行 dos 命令来 ftp aa 文件。从技术上讲,它调用一个 BAT 文件,该文件调用一个执行 DOS 代码的 CMD 文件。这取决于 CMD 文件。如果我对路径进行硬编码,CMD 字段将起作用,但我需要动态指定文件的路径。
BAT文件...
ftp.exe -s:%~dp0\mycmdfile.cmd
并在cmd文件中...
open <my ost>
<my user name>
<my pw>
quote site cyl pri=1 sec=1 lrecl=1786 blksize=0 recfm=fb retpd=30
put <here is where I need the dynamic path> + localfilename remotefilename
退出
I am trying to use c# in .net to run dos commands to ftp a a file. Technically, it calls a BAT file which calls a CMD file which executes the DOS code. It was up to the CMD file. The CMD fiel will work if I hardcode the path, but I need to dynamically specify the path of the file.
BAT File...
ftp.exe -s:%~dp0\mycmdfile.cmd
And in the cmd file...
open <my ost>
<my user name>
<my pw>
quote site cyl pri=1 sec=1 lrecl=1786 blksize=0 recfm=fb retpd=30
put <here is where I need the dynamic path> + localfilename remotefilename
quit
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想向 Zachary 补充一点,您可以使用 %1、%2 等引用 bat 内的命令行变量。
%~dp0
语法仅适用于 Windows 2000(如果我没记错的话)。要引用另一个目录中的文件,只需更改到一个目录,只需cd
到该目录,然后从中调用命令。I would add to Zachary that you can refer to command line vars inside bat with %1, %2, and so on.
%~dp0
syntax is only available from Windows 2000 (if I remember it right). To refer to files from another directory just change to a directory justcd
to that directory and then invoke command from it.您可以将参数传递给批处理文件。如果我没记错的话,您可以通过将它们放在调用批处理文件之后并使用空格分隔符(例如 C:\mycmd.bat Var1 Var2)来传递它们。然后您可以使用它们来重建您的文件路径。
You can pass in arguments to a batch files. If memory serves me right, you pass them in by putting them after the call to the batch file and using space delimiters (e.g. C:\mycmd.bat Var1 Var2). You can then use those to reconstruct your file path.