Question:
Is there a way to shorten this batch file?
2012-02-28 16:29:04 UTC
@echo off
cd\
cd Documents and Settings\file\file
notepad.txt
exit

I am really new to batch files and was asked to make one at work to help out with opening a file that people are having trouble opening. Is this above command sufficient or is there a better way or even is there a shorter way? Is it possible to some how use a command to open this file on all computer on the network? Any help well and truly appreciated.

Thank you
Four answers:
rowlfe
2012-02-28 17:24:07 UTC
First thing, spaces are delimiters in MSDOS so no spaces are allowed in a directory name unless the name is enclosed in quotation marks like this:



cd "\documents and settings\file\file"



Without the " marks, it would go to \documents if there is one.



I am guessing you want to run the NOTEPAD program to edit a file called DOCUMENT.TXT. Your line of "notepad.txt" makes no sense as you write it. OK, so here is what I suggest:



@echo off

c:

cd "\documents and settings\file\file"

c:\windows\notepad.exe document.txt

exit



What this will do is first change the default drive to C: if it isn't already, and then change the default subdirectory and then launch the notepad program to open the file "document.txt". When you close notepad, the batch file ends. Make sure you set the properties on the shortcut you use to execute this file so it closes the command window when notepad.exe ends.



For a network drive, simply change the initial "C:" to the drive letter of the network drive, and change the CD path accordingly to the network location of the DOCUMENT.TXT file. Then, make sure the path is set correctly to call notepad.exe from where ever it is located, or use the full drive and directory to get to the editor. On my laptop, the location of the program is



"c:\winnt\notepad.exe"



The only way that "notepad" by itself will launch the program is if it is "in the path" set by default in a command window. To see what the default path IS, simply open a command window and type PATH and press return. It will show you where windoze looks to find a program without the full drive and directory in front of the program name. You can place this batch file anywhere that people all have access to on the network. Then, you create a shortcut to point to the batch file on each local machine that needs to run it. It is NOT a good idea to have multiple people editing a single common file without some kind of version control. Without some kind of version control, if two people are editing the same file, whoever saves last overwrites any other changes made by anyone else.



.
Simon Belmont
2012-02-28 16:39:17 UTC
Hi, you can change your batch to the following:

start c:\documents and settings\file\file\notepad.txt



it should open the file and close the dos prompt window at the same time.



Hope it helps.
Jake
2012-02-28 19:09:55 UTC
@echo off

start "c:\documents and settings\file\file\notepad.txt"

(quotations make a BIG difference.)



Now, I'm not sure if this is the right directory, but if you want it to work on every machine, you might want to try:

start "%userprofile%\file\file\notepad.txt"
?
2016-10-14 16:38:31 UTC
you do not specify what software you're beginning the report with, so i can't be completely specific yet you could supply the full filepath which incorporate the filename in case you utilize double-expenditures to delimit it. In different words, some thing including (which incorporate double expenditures): "C:UsersSamDesktopfilename.ext"


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...