Community discussions

MikroTik App
 
luca1234567
newbie
Topic Author
Posts: 27
Joined: Tue May 15, 2018 1:27 am
Contact:

Super-Easy script to create dir

Sun Nov 29, 2020 2:52 am

I found 4 super-easy, it may also customized, scritp to create a full path of a folder.

- NO need of FTP service enable
- NO need of Firewall config
- NO need of User\Password config
- NO need external scritp
- May be easy included in other script

{
:local CreateDirNewPath "NewDir/NewSubDir"
:do {
  /tool fetch address=127.0.0.1 port=443 mode=https src-path="NotExist" dst-path=($CreateDirNewPath."/NotExist")
  /file remove ($CreateDirNewPath."/NotExist")
 } on-error={ }
}

{
:local CreateDirNewPath "NewDir/NewSubDir"
:do {
  /tool fetch https://127.0.0.1/NotExist dst-path=($CreateDirNewPath."/NotExist")
  /file remove ($CreateDirNewPath."/NotExist")
 } on-error={ }
}

This is if you not want "status:failed" in terminal.
{
:execute {
  :local CreateDirNewPath "NewDir/NewSubDir"
  :do {
    /tool fetch address=127.0.0.1 port=21 mode=ftp src-path="NotExist" dst-path=($CreateDirNewPath."/NotExist")
    /file remove ($CreateDirNewPath."/NotExist")
   } on-error={ }
 }
}

This if you can use global variable
{
:global CreateDirNewPath "NewDir/NewSubDir"
:execute {
  :do {
    /tool fetch address=127.0.0.1 port=21 mode=ftp src-path="NotExist" dst-path=($CreateDirNewPath."/NotExist")
    /file remove ($CreateDirNewPath."/NotExist")
   } on-error={ }
 }
}


I suggest to Mikrotik to correct also the scritp to https://wiki.mikrotik.com/wiki/Script_t ... _directory

Best regards
Last edited by luca1234567 on Sat Dec 12, 2020 1:22 am, edited 1 time in total.
Best regards.
 
User avatar
satman1w
Member Candidate
Member Candidate
Posts: 168
Joined: Mon Oct 02, 2006 11:47 am

Re: Super-Easy script to create dir

Mon Nov 30, 2020 1:34 pm

...or you can create folder on your desktop and just drop it in your Winbox / Files wherever you want..
 
User avatar
mozerd
Member
Member
Posts: 481
Joined: Thu Oct 05, 2017 3:39 pm
Location: Canada
Contact:

Re: Super-Easy script to create dir

Mon Nov 30, 2020 2:01 pm

Following is SUPER easy way of creating a dir using Terminal
/ip smb shares add name=sharethis directory=moab
/ip smb shares remove [find name=sharethis]
The 1st directive will create the directory while the 2nd directive will remove the share that is not needed.
Last edited by mozerd on Mon Nov 30, 2020 3:24 pm, edited 1 time in total.
 
User avatar
bpwl
Forum Guru
Forum Guru
Posts: 1239
Joined: Mon Apr 08, 2019 1:16 am

Re: Super-Easy script to create dir

Mon Nov 30, 2020 2:14 pm

Make and delete a backup, in the wanted directory.?
 
luca1234567
newbie
Topic Author
Posts: 27
Joined: Tue May 15, 2018 1:27 am
Contact:

Re: Super-Easy script to create dir

Mon Nov 30, 2020 3:31 pm

@satman1w: This is a method to create it automaticaluy via scritp, or you want that the router call you when it need to create a directory ?

@mozerd: I test the method /ip smb shares on RouterOS v4. and it CANNOT create new sub-folder like NewDir/NewDir2/NewDir3/ in one command. Can you try.

@bpwl: Why write not wanted data, to next delete ?

WHY mikrotik not implement a full set of command to manage file ?
Like copy file, move file, copydirectory, move directory, create directory, etc.

WHY ???
Best regards.
 
User avatar
mozerd
Member
Member
Posts: 481
Joined: Thu Oct 05, 2017 3:39 pm
Location: Canada
Contact:

Re: Super-Easy script to create dir

Mon Nov 30, 2020 3:52 pm

@mozerd: I test the method /ip smb shares on RouterOS v4. and it CANNOT create new sub-folder like NewDir/NewDir2/NewDir3/ in one command. Can you try.
@luca1234567
You are 100% correct .... I am not able to create new sub-folders like described ..... no problem with root folders.
 
User avatar
CZFan
Forum Guru
Forum Guru
Posts: 1937
Joined: Sun Oct 09, 2016 8:25 pm
Location: South Africa, Krugersdorp (Home town of Brad Binder)
Contact:

Re: Super-Easy script to create dir

Mon Nov 30, 2020 11:38 pm

Use winscp to create folder/sub folder?
MTCNA, MTCTCE, MTCRE & MTCINE
 
luca1234567
newbie
Topic Author
Posts: 27
Joined: Tue May 15, 2018 1:27 am
Contact:

Re: Super-Easy script to create dir

Mon Nov 30, 2020 11:43 pm

@CZFan
Use winscp to create folder/sub folder?
I repeat:
@satman1w: This is a method to create it automaticaluy via scritp, or you want that the router call you when it need to create a directory ?
Last edited by luca1234567 on Tue Dec 01, 2020 10:16 pm, edited 1 time in total.
Best regards.
 
User avatar
satman1w
Member Candidate
Member Candidate
Posts: 168
Joined: Mon Oct 02, 2006 11:47 am

Re: Super-Easy script to create dir

Tue Dec 01, 2020 2:37 pm

I repeat:
@satman1w: This is a method to create it automaticaluy via scritp, or you want that the router call you when it need to create a directory ?
[/quote]

You're right, but I never had a need to create folders dynamically on Mikrotik router... When that will happen, I will definitely use one of your scripts.
:-)

regards

Who is online

Users browsing this forum: cashwu and 50 guests