I am working on a document import utility that imports a text document from a specific location. The filename of the document is unknown and I need to find out how to determine the name of the file and make it a temporary value in my script so that it knows what the file name is so that it can ultimately open it in notepad automatically. I tried using *.txt
to see if notepad would just open the first file matching this filter within the working directory but it doesn't work. How do I get and then set this unknown filename variable once the document has been copied to the working directory? Here is the code I have for the function so far:
@ECHO OFF
:CHECK
IF EXIST "*.txt" GOTO :AUTOEDIT
IF NOT EXIST "*.txt" GOTO :RUN
:AUTOEDIT
%SYSTEMROOT%\Notepad.exe "*.txt"
GOTO :END
:RUN
%SYSTEMROOT%\Notepad.exe
GOTO :END
END
:AUTOEDIT
is run the mystery file will already be present. Essentially, I need to get a specific file's name after it's imported to the folder this script is in, once imported I need to get the file's name then use that as a variable to run in conjunction with notepad. The document in question will have a timestamp based name, so it will be different whenever it has been imported to be edited.