tags:

views:

41

answers:

1

I'm trying to open a file in it's default editor after the user has created the file. So far my script is:

@echo off
@echo --- Create A New File ---
@echo -
@echo Where should we put the new file?
set /p fileLocation=@ %UserProfile%\
@echo -
@echo What do you want to call your new file?
set /p fileName=@ 
@echo -
@echo Almost Done! What is the files extension?
set /p extension=@ .
@echo -
copy NUL "%UserProfile%\%fileLocation%\%fileName%.%extension%"

(ignore the extra echos and '@' those are just for fun)

After I click the file, it does the command: Choose Location > Choose File Name > Choose File extension. I'm almost done on what I want but theres one last thing. How can I get the file name that I created and then open in its default text-editor?

+4  A: 

You can use start to open the file with the associated application.


Resources :

Colin Hebert
How can I get the created file and then use that?
omnix
You already have your file name, its `"%UserProfile%\%fileLocation%\%fileName%.%extension%"` so just start it.
Colin Hebert
noob here, how do I start it? Where do I put in 'start'?
omnix
in your script; `start "%UserProfile%\%fileLocation%\%fileName%.%extension%"`.
Colin Hebert
Added at the end, it opens up another cmd, not the file.
omnix
Then you should use `assoc` before to associate an extension to a file type and `ftype` to associate a file type to an application.
Colin Hebert
can you put that together for me? I really do not understand it :( thanks so much for helping
omnix
`assoc .myExt = MyNewFileType` and `FTYPE MyNewFileType=C:\NotePad.exe` will associate the ".myExt" extension to NotePad.exe, if you do `start anyFile.myExt` it will open it in NotePad.exe
Colin Hebert
How would I insert that in the script?
omnix
The thing is you can't really do that. You must know the file type association before starting your application. So you must manually execute these commands to do the association first. Then you'll be able to call the start method anytime
Colin Hebert
Okay thanks for the help!
omnix
Hm, how about.. get the fileLocation that I entered and then use the start command?
omnix
If it didn't work, it's because your file extension wasn't associated with an application, not because of your file location
Colin Hebert