I have created a script that creates a $mkdir global function to create directories. Once you have run the script, you can write this on the command line:
$mkdir some/new/folder
It builds on this code found on the official Wiki, which uses FTP via /tool fetch to create the directory tree. This function handles cases like the FTP service being disabled, cleans up after itself even if an error occurs, and is easy to install.
or here’s a snippet you can copy and paste in the terminal to easily create the function and a scheduler entry that runs on startup to make sure that $mkdir is always available.
# if you trust strangers on the internet
# for extra safety, the commit in the below URL is pinned to 2fa4d317b2dbf2b12f8ee1970403f390ea560c99
{
:local result [/tool fetch \
url="https://raw.githubusercontent.com/phistrom/routeros-mkdir/2fa4d317b2dbf2b12f8ee1970403f390ea560c99/persist_create_mkdir_function.rsc" \
as-value output=user];
:local script [:parse ($result->"data")]
$script;
}
If using $mkdir in a script, remember you have to include it with
I agree that the script is long and scary looking, but the idea was to give you a very robust function that should run no matter what your settings are. It has to set up and tear down a temporary group, user, firewall rules, and check to see if it needs to briefly toggle on your FTP service, and then toggle it back off (or restore whatever your “available from” IP ranges were). It also has to chop the input string, i.e. if you said $mkdir /some/path/, it has to convert that to $mkdir some/path. Plus I left in a lot of commenting to give as much transparency as possible into what is going on.
One could theoretically cut this down to basically the same size as the original script, but it wouldn’t be nearly as portable.
I’m sorry, but I just made an account specifically to reply to this.
This must be the most condescending disgustingly customer-unfriendly response I’ve seen in a long long while. Are you actually for real??
Besides the fact that folders are an EXTREMELY common and useful way to store files, and it’s in no freaking way an anomaly for someone to want to store their files separated in directories, what’s it up to you? Even if it wasn’t necessary to store files in separate directories, it’s in no way any business of yours to second guess something this common.
This is…
wow, this is just disgusting.
This is really a shitty script, full of “on-error={}”, do not count “flash”, and other nonsense
like creating firewall rules on filter, nat, mangle, raw, temporary user group, temporary user, enabling ftp service, etc. etc. etc. …
And the script must have all the control of device because “policy” is required fro create and manage users
And if something go wrong delete all firewall filter / nat / mangle / raw rules
Simply one command (ignoring SMIPS),
simply create a recurrency & test foreach / on path
I have made some test with “/ip smb shares”, but the problem is that this function can not create more then one subfolder of a subfolder.
For example, if not exist subfolder and not exist sub-subfolder, it can not be created in one istrution the folder /flash/A/B.
But must be created /flash/A and next /flash/A/B
In the metod I use it can be created in one iteration.
search tag # rextended create directory and subdirectory
the function return an array for check on calling script if the path are created or not (and why not)
if the result ($results->0) containing OK, on ($results->1) are present the name of folder/path created
35 lines and also with sanitizing input and “flash” folder on consideration