1

I am trying to access a text file using batch when a user enters a certain command. I have tried doing

start E:\Programming\Important\Folder\Textfile
Cls

And it closes the cmd window but wont open the file. Does someone mind telling me what I did wrong? (sorry for the code not being in the gray box im using the web browser on phone)

Tyler
  • 13
  • 1
  • 1
  • 6

2 Answers2

2

I guess the problem is Textfile has no file extension, so windows does not know how to open it. Instead of using start you could use the notepad command, as notepad.exe is in the search path of the system, you can simply write:

notepad 'E:\Programming\Important\Folder\Textfile'

This will open your file.

Nidhoegger
  • 4,973
  • 4
  • 36
  • 81
  • better to put single quotes around filepath – Eddy Jawed Jan 14 '16 at 17:26
  • @EddyJawed that won't work because [single quotes don't have any meaning in cmd](https://stackoverflow.com/q/24173825/995714). You need to use double quotes if there are special characters in the file name – phuclv Jul 17 '18 at 05:10
0

You can do that easily with PowerShell, like so:

say we want to open 2 files in Sublime Text:

Start-Process -FilePath "C:\Program Files\Sublime Text 3\subl.exe" -ArgumentList D:\PathToMyFile\myFile.txt, D:\PathToMySecondFile\myFile.txt
tanuk
  • 498
  • 9
  • 10