Is it possible to arrange this scenario:
script checks if some_file.rsc exists in /
if yes -> do some job
else -> exit
Thanks!
:while ([:len [/file/find where type=ncfg]]=0) do={:delay 1}; :put "File with .ncfg is present"
[/file/find where type=ncfg]
Pardon, had to adjust to the exact file type name to type=".ncfg file" but you probably guessed it alreadyBefore post something, better test it, not?
# if the file iphistory.txt can be on root
:global filename "iphistory.txt"
:global findresult [/file find where name="$filename"]
:if ([:len $findresult] > 0) do={
:put "file $filename exist"
}
# if the file iphistory.txt can be on flash or another subdirectory
:global filename "flash/myfiles/iphistory.txt"
:global findresult [/file find where name="$filename"]
:if ([:len $findresult] > 0) do={
:put "file $filename exist"
}
:global filename "iphistory.txt"
:global findresult [/file find where name~"(^|/)$filename\$"]
:if ([:len $findresult] > 0) do={
:put "file $filename exist"
}
# if the extension is not recognized from RouterOS
:global fileext ".txt"
:global findresult [/file find where type="$fileext file"]
:if ([:len $findresult] > 0) do={
:put "found $[:len $findresult] file(s) with $fileext extension"
}
# if the extension is recognized, like backup, from RouterOS
:global filetype "backup"
:global findresult [/file find where type=$filetype]
:if ([:len $findresult] > 0) do={
:put "found $[:len $findresult] $filetype file(s)"
}
# if the extension is not recognized from RouterOS
:global fileext ".txt"
:global subdir "flash/myfiles/"
:global findresult [/file find where name~"^$subdir" and type="$fileext file"]
:if ([:len $findresult] > 0) do={
:put "found $[:len $findresult] file(s) with $fileext extension inside the folder $subdir"
}
# if the extension is recognized, like backup, from RouterOS
:global filetype "backup"
:global subdir "flash/myfiles/"
:global findresult [/file find where name~"^$subdir" and type=$filetype]
:if ([:len $findresult] > 0) do={
:put "found $[:len $findresult] $filetype file(s) inside the folder $subdir"
}
Similarly, is it possible to check whether a folder exists?
I want to check if /flash/ exists or not before doing my stuff (some cards have it, other don't).
:global subdir "flash"
:global findresult [/file find where name~"^$subdir"]
:if ([:len $findresult] > 0) do={
:put "found $[:len $findresult] the folder $subdir exist!"
}
:if ($LastRun = $date) do={
/file
:foreach item in=[find where name~"usb" and type=disk] do={
:local usbName [get $item name]
:local usbState
:if ([:len $usbName] > 0) do={
:set usbState "true"
} else={
:set usbState "false"
:put $usbState
}
}
}