Windows environment variable %USERPROFILE% in File URI Scheme (three slashes) - batch-file

In Notepad++ I have a link to a batch file using a "File URI Scheme with three slashes" convention as follows:
file:///C:/Users/john.doe/some_folder/test%20file.bat
When I double-click on it, the link works (i.e. the double-click runs the batch file).
I want to modify the File URI to incorporate %USERPROFILE% like so:
file:///%USERPROFILE%/some_folder/test%20file.bat
This doesn't work. Is there some character I can add or remove or escape to make it work?
UPDATE: since making this post, I've learned that Notepad++ doesn't expand Windows environment variables.

Related

Quickest way to create a .bat file (as .txt)

I have a couple lines of code in a batch file in Windows 10 that open a session of Octave, and load a script that uses design parameters contained in a .txt file. The batch file is named (for example) "Design123.bat", and when Octave runs, it automatically finds the design parameters in the file "Design123.txt" by simple string manipulation of the file name, i.e. strrep(filename,".bat",".txt"), where filename = '%~dpn0' is passed to Octave from the batch file. This allows for the contents of the batch file to stay simple and constant, and the file name of the batch file is the only thing tying it to the .txt file.
I do all of this to allow running the Octave script by double-clicking the batch file for convenience, instead of being forced to use the more tedious process of uigetfile in Octave. This works very well, but the catch is that I have to place a copy of the batch file in the same directory with the design (.txt) files (of which there are thousands, but each within their own directory) and give it the same file name to get it to work. Is there a way to quickly create the batch files somehow? The most ideal situation I can think of is to be able to right-click (or somehow select) a .txt design file, and create a batch file (replacing .txt with .bat) and place my lines of code into it.
Any ideas? I have coding experience, but only in software packages like VBA and Octave, not within operating systems themselves, though certainly willing to learn if I could get pointed in the right direction. The design file names follow a distinctive pattern, so they could be filtered easily within an operation on the active "File Explorer" window in Windows 10, if something like that is possible. Thanks in advance.
You might want to compose the answer to your question from calling the script on the right click and running the .m script with command line arguments.
If that fails, uigetfile is certainly not the only method to get file. At the very least you could always copypaste a path string to a folder from explorer to octave function call.
Finally, I guess I'll mention the existence of octave-cli which runs in terminal instead of gui. It might be better suited for running non interactive scripts.

Move files into a jar with a .bat script

Just the title. I'm trying to make a .bat file that moves stuff into a .jar, but I have no idea what to do, or even if it's possible. If it's possible, could I be pointed towards the information that would allow me to create such a .bat file? Thanks.
"A .jar file is just a .zip file with a different extension. Use any zip tool that takes command line parameters like WinZip or 7-Zip, and call it from your batch file passing it the right information in the parameters to add the files. Once you pick your utility app, you can read its documentation to find out what parameters it takes and what order they should be in. (Or more easily, you could just open the file in WinZip or 7-Zip and drag and drop the files in using Windows Explorer and save the time and effort.)" - From Ken White, in a comment
Thank you Ken White, for your answer.
While I do agree not using commands is more convenient, I can't automate moving files without commands or code.
This is a valid answer. But for some reason an arbitrary restriction won't let me mark this post as the answer until two days.

Call .bat file from anywhere in the directory using python

I need to call a .bat file from anywhere in the directory without including the specific directory in the script. You'll just need to specify the name of .bat file you want to call and then run. Is this possible?
Add the .bat file's directory into your PATH.
This is an article for you.
http://www.computerhope.com/issues/ch000549.htm
do you mean calling a script without specifying the exact location from commandline?
there are two ways:
add it to your path (eg: set it in your PATH environment variable)
setup an alias/some sort of shortcut in your bashrc/whatever CLI you are using (since you are using windows, one example would be to setup a cmdlet in windows powershell or something)

Access context menu items from windows batch file

Okay I currently need to check about 200 files, so of course i want to automate as much as i can. the software I need to use to inspect them does not seem to have a command line interface, so I am currently stuck right-clicking them and clicking edit.
Is there any way to access that edit command from command line, so I can automate this process, or am I stuck opening 200 files like this.
Okay I figured it out, and here's how I did it!
Go to regedit, and find the file extension im trying to deal with in HKEY_CLASSES_ROOT
then inside the folder for the file extension i found the name of the folder of the program this filetype uses, and that folder was also located on HKEY_CLASSES_ROOT.
Then inside that folder is a "shell" folder wherein all of the contextual options are located.
That shell folder had an element called "edit" and that element contained a shell command that was used behind the scenes to launch the editor with the specific file.
Now I can write my batch script with this command!

Batch file to list and copy files to another directory

I'm a novice with batch files, even though I've had a computer since the mid 1980s. I need to create a (preferably simple) batch file that will list all the directories on drive D:\TAR\ (to a text file maybe?) and append the extension .tar to the directories names. Then I would like to copy all the .tar files(in the text file that was created) on E:\Incomplete\File1.tar to F:\ToComplete\ directory.
I tried doing it from a DOS command prompt, but I couldn't figure out how to put the .tar extension on the directory names and do the copying. I've been googleing, and searching on this site, with no similar problems.
Is there a list on the net that list most of the commands that can be used in .bat files, for example #echo, end, if, then, etc.? I would like to be able have it as a guide. I would appreciate any and all help.
Thank You.
The command prompt has a builtin help command that provides a decent listing of common commands, and each command supports the /? switch to attain more information on it.
You will typically use the for command to enumerate the contents of a directory, and if you need to perform string manipulation on the directory entries you will probably find the command prompt's "delayed expansion" feature useful. This feature is off by default, but can be enabled for an interactive session by running cmd /v:on. (Enabling this feature permanently requires a registry setting.)
In terms of your specific problem here, when you say "all the directories under D:\TAR\", would that be a recursive operation?

Resources