logo elektroda
logo elektroda
X
logo elektroda

CMD Command to Input Filename & Open TXT File in Default Text Editor Window

Elektronik2001s 14988 6
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 16613088
    Elektronik2001s
    Level 8  
    Hello!
    As in the subject, I would like to ask if there is such a command or code which after running the file will ask you to enter the file name and then press the ENTER key will open it in the normal window ... everywhere I search but unfortunately I can not find anything. I would like to make a program that can easily open a text program.
    Thanks for help in advance
  • ADVERTISEMENT
  • #2 16613154
    md37
    Level 10  
    I will write you a ready program:

    
    @echo off
    color 0a
    title Program
    
    :a
    echo Podaj sciezke do pliku, który chcesz otworzyć:
    set /p "cho=>"
    
    notepad.exe %cho%
    goto a
    
  • ADVERTISEMENT
  • #3 16613855
    Elektronik2001s
    Level 8  
    The program works, thank md37 colleague for help!
  • ADVERTISEMENT
  • #4 16650791
    Elektronik2001s
    Level 8  
    Hello and thank you very much for unlocking the topic.
    Well, I would like to present a problem that concerns this program.
    The program that opens the .txt files, that is notebook works sensational, but I thought to expand it a little.
    I have made several sections where each has to open a different file type. Unfortunately, when you try to open the .mp4 and .mp3 files with Windows Media Player, this is not the case. After confirming the location path with ENTER, the file will not open and the batch file will go to the place I indicated.
    Is this problem solved somehow? CMD Command to Input Filename & Open TXT File in Default Text Editor Window
  • ADVERTISEMENT
  • #5 16664899
    md37
    Level 10  
    Instead of wmplayer.exe% cho%, type "C: \ Program Files \ Windows Media Player \ wmplayer.exe"% cho% along with the quotes.
  • #6 16665457
    dt1
    Admin of Computers group
    You can also try typing instead of the wmplayer command:

    start "" "%cho%"


    This should run the file in the default program assigned to it. Basically, you can simplify the program and you do not have to crash the program into a separate condition for each extension, because Windows itself will take care of launching the program.
  • #7 16665689
    Elektronik2001s
    Level 8  
    Hello
    After a few attempts this way was achieved:
    start wmplayer.exe% cho% where in the place% cho% appears the path I entered
    And analogously for each section only that of another program.
    The code in the post
    dt1 wrote:
    You can also try typing instead of the wmplayer command:

    Code:
    start "" "% cho%"


    This should run the file in the default program assigned to it. Basically, you can simplify the program and you do not have to crash the program into a separate condition for each extension, because Windows itself will take care of launching the program.

    It seems much better because in a situation of changing for some reason the default program will not need to be changed in the batch file or further in the .exe file after processing.

Topic summary

The discussion revolves around creating a CMD batch file that prompts the user to input a filename and opens it in the default text editor or associated application. A user initially requested assistance in developing such a program. A solution was provided using a simple batch script that utilizes the `notepad.exe` command to open .txt files. The user later expanded the program to handle different file types, including .mp4 and .mp3, but encountered issues with Windows Media Player. Suggestions included specifying the full path to `wmplayer.exe` and using the `start` command to open files with their default applications, which proved to be a more efficient solution. The user confirmed the effectiveness of the revised approach.
Summary generated by the language model.
ADVERTISEMENT