简体   繁体   English

查找具有特定扩展名的文件,然后使用批处理文件在程序中打开文件

[英]Find file with certain extension and open the file in a program using a batch file

I'm trying to search for a file that ends with *.ac and open that file in a program. 我正在尝试搜索以* .ac结尾的文件,并在程序中打开该文件。 There will always just be one file with this extension. 始终只有一个带有此扩展名的文件。 The directory where the bat file will search is always the directory where it's running from. bat文件将在其中搜索的目录始终是其运行目录。

Currently this works: 目前这有效:

@echo off
for /r "%CD%" %%a in (*) do if "%%~nxa"=="myFileName.ac" set p=%%~dpnxa
start /d "C:\Program Files (86)\CaseWare\" cwin32.exe "%p%"

But the myFileName.ac will always have a different name. 但是myFileName.ac将始终具有不同的名称。

I tried to change it to *.ac but then it doesn't work :( 我试图将其更改为* .ac,但随后不起作用:(

@echo off
for /r "%CD%" %%a in (*) do if "%%~nxa"=="*.ac" set p=%%~dpnxa
start /d "C:\Program Files (86)\CaseWare\" cwin32.exe "%p%"

Any help please? 有什么帮助吗?

for /r "%CD%" %%a in (*.ac) do set p=%%~dpnxa

should find that elusive file. 应该找到那个难以捉摸的文件。

@echo off
for /r "%CD%" %%a in (*.ac) do start /d "C:\Program Files (86)\CaseWare\" cwin32.exe "%%~dpnxa"

should process it. 应该处理它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM