I believe you want to Associate .C Files with a batch script.
EG: So that if you double-click the .c file, or call the .c file on the command line, it will be passed as an argument to the CMD Script which you will have GCC run in.
This is possible, both through GUI and through CMD.
Here is an example of how you would accomplish this:
Optional: Backup old association for .c files to be able to restore it later if you want:
REM Backup old association for .c files to be able to restore it later if you want:
Assoc .c >>"%temp%\BKP_Assocs.txt"
Create Custom FileType that points to your CMD Script. -- This links the Filetype to the CMD Script, you will need to provide the full path with quotes for the cmd script:
FType c.cmd="C:\Path\To\YourScript.cmd"
Associate the .c file extension with the custom file type created in FType, allowing it to open in the CMD Script:
Assoc .c=c.cmd
Once you have run the above, you may Double-click on any .c
file say "C:\Somefile.c" and it will have it's address passed to the .CMD
Script you specified eg C:\Path\To\YourScript.cmd
You can also type "C:\Somefile.c"
on the CLI and get the file to open in the C:\Path\To\YourScript.cmd
script as a path passed as an argument.
Below is an example script to allow me to show you it works in the Example output following this script, it will spit out the info provided when you double-click a .c
file of your choice for testing:
@ECHO OFF
ECHO(%~n0:
ECHO(%~n0: =====================
ECHO(%~n0: Begin Script "%~f0"
ECHO(%~n0: =====================
ECHO(%~n0:
ECHO(%~n0: The Full File Path That opened this script is:
ECHO(%~n0: %1
ECHO(%~n0:
ECHO(%~n0: The Full File Path That opened this script, without Quotes, is:
ECHO(%~n0: %~1
ECHO(%~n0:
ECHO(%~n0: ---------------------------------------------------------
ECHO(%~n0: File Name: "%~n1"
ECHO(%~n0: File Path: "%~dp1"
ECHO(%~n0: File Size: "%~z1"
ECHO(%~n0: File Ext: "%~x1"
ECHO(%~n0: File Date: "%~t1"
PAUSE
When I double-click on an Example .c File The result is:
C_Parser:
C_Parser: =====================
C_Parser: Begin Script "C:\Admin\C_Parser.cmd"
C_Parser: =====================
C_Parser:
C_Parser: The Full File Path That opened this script is:
C_Parser: "C:\Admin\testfile.c"
C_Parser:
C_Parser: The Full File Path That opened this script, without Quotes, is:
C_Parser: C:\Admin\testfile.c
C_Parser:
C_Parser: ---------------------------------------------------------
C_Parser: File Name: "testfile"
C_Parser: File Path: "C:\Admin\"
C_Parser: File Size: "35"
C_Parser: File Ext: ".c"
C_Parser: File Date: "07/09/2019 03:20 PM"
Press any key to continue . . .