Advertisement
Advertisement


Open text file and program shortcut in a Windows batch file


Question

I have two files in the same folder that I'd like to run. One is a .txt file, and the other is the program shortcut to an .exe. I'd like to make a batch file in the same location to open the text file and the shortcut then close the batch file (but the text file and program remain open).

I tried this with no luck:

open "myfile.txt"
open "myshortcut.lnk"

Also didn't work:

start "myfile.txt"
start "myshortcut.lnk"
2018/11/03
1
38
11/3/2018 11:11:31 PM

Accepted Answer

I was able to figure out the solution:

start notepad "myfile.txt"
"myshortcut.lnk"
exit
2011/07/11
62
7/11/2011 11:21:35 PM


Don't put quotes around the name of the file that you are trying to open; start "myfile.txt" opens a new command prompt with the title myfile.txt, while start myfile.txt opens myfile.txt in Notepad. There's no easy solution in the case where you want to start a console application with a space in its file name, but for other applications, start "" "my file.txt" works.

2011/07/11

The command-line syntax for opening a text file is:

type filename.txt

File types supported by this command include (but are not limited to): .doc, .txt, .html, .log

If the contents is too long, you can add "|more" after "type filename.txt", and it will pause after each screen; to end the command before the end of the file, you can hold Ctrl + C.

2018/11/03

I use

@echo off
Start notepad "filename.txt"
exit

to open the file.

Another example is

@echo off
start chrome "filename.html"
pause
2018/11/03

You can also do:

start notepad "C:\Users\kemp\INSTALL\Text1.txt"

The C:\Users\kemp\Install\ is your PATH. The Text1.txt is the FILE.

2018/11/03

"location of notepad file" > notepad Filename

C:\Users\Desktop\Anaconda> notepad myfile

works for me! :)

2015/09/10

Source: https://stackoverflow.com/questions/6657777
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]