os

The system operation module belongs to the built-in module. It can be called directly by the script scope without using import.

This module is also a native module of lua, and xmake has been extended to provide more practical interfaces.

âš  Only some readonly interfaces (for example: os.getenv, os.arch) in the os module can be used in the description scope. Other interfaces can only be used in the script domain, for example: os.cp, os.rmetc.

edit

os.addenv

bool os.addenv(string name[, string ...])

Add values to one environment variable

-- Add 'bin' to PATH
local ok = os.addenv("PATH", "bin")

When adding several values, they are concatenated depending on the current os.

-- MY_ENV=value1;value2 on windows,
-- MY_ENV=value1:value2 on linux
os.addenv("MY_ENV", "value1", "value2")

Introduced in version 2.1.5

See also

os.addenvp, os.addenvs, $(env), os.setenv, os.getenv, os.joinenvs

edit

os.addenvp

bool os.addenv(string key, table values, string separator)

Add values to one environment variable with a given separator

-- Add 'bin$lib' to PATH
local ok = os.addenvp("PATH", {"bin", "lib"}, '$')

Introduced in version 2.1.5

See also

os.addenv, os.addenvs

edit

os.addenvs

table os.addenvs(table envs)

Add environment variables to current envs, return the all old envs

os.setenvs({EXAMPLE = "a/path"}) -- add a custom variable to see addenvs impact on it

local oldenvs = os.addenvs({EXAMPLE = "some/path/"})
print(os.getenvs()["EXAMPLE"]) --got some/path/;a/path
print(oldenvs["EXAMPLE"]) -- got a/path

Introduced in version 2.5.6

See also

os.addenv, os.addenvp

edit

os.arch

string os.arch()

Get current system architecture

That is the default architecture of the current host system, for example, I execute xmake on linux x86_64 to build, then the return value is: x86_64.

Introduced in version 2.0.1

See also

os.is_arch, is_arch, os.subarch

edit

os.args

string os.args(table aguments[, table opt])

Format arguments to be passed to a process

Valid fields for opt are:

e.g:

local cmd = "program"
cmd = cmd .. " " .. os.args({"--value=hello, world", "-i", 123})
-- cmd is:
--     program "--value=hello, world" -i 123

Set escape to true if you want to escape backslashes:

print(os.args({"path=C:\\Folder\\Subfolder"}))                  -- got path=C:\Folder\Subfolder
print(os.args({"path=C:\\Folder\\Subfolder"}, {escape = true})) -- got path=C:\\Folder\\Subfolder

Set nowrap to true if you don't want to wrap quotes:

print(os.args({'path="C:/Program Files/xmake"', "-i", 42}))                  -- got "path=\"C:/Program Files/xmake\"" -i 42
print(os.args({'path="C:/Program Files/xmake"', "-i", 42}, {nowrap = true})) -- got path=\"C:/Program Files/xmake\" -i 42

See also

os.argv

edit

os.argv

table os.argv(string command[, table opt])

Parse a command and split its arguments

Valid fields for opt are:

e.g:

local args = os.argv('cmd --value="hello, world" -i 123')
-- got {
--   "cmd",
--   "--value=hello, world",
--   "-i",
--   "123"
-- }

args = os.argv('cmd --value="hello, world" -i 123', {splitonly = true})
-- got {
--   "cmd",
--   '--value="hello, world"',
--   "-i",
--   "123"
-- }

See also

os.args

edit

os.atexit

nil os.atexit(function on_exit)

Register exit callback

e.g:

os.atexit(function (ok, errors)
    print(ok, errors)
end)

See also

os.exit

edit

os.cd

string os.cd(string dir)

Enter the specified directory

This operation is used for directory switching and also supports built-in variables, but does not support pattern matching and multi-directory processing, for example:

-- Enter the temporary directory
os.cd("$(tmpdir)")

If you want to leave the previous directory, there are several ways:

-- Enter the parent directory
os.cd("..")

-- Enter the previous directory, equivalent to: cd -
os.cd("-")

-- Save the previous directory before entering the directory,
-- then use it to cut back directly after the level
local oldir = os.cd("./src")
...
os.cd(oldir)

Introduced in version 2.0.1

See also

os.curdir

edit

os.cp

nil os.cp(string src, string dst[, table opt])

Copy files or directories

The behavior is similar to the cp command in the shell, supporting path wildcard matching (using lua pattern matching), support for multi-file copying, and built-in variable support.

Valid fields for opt are:

e.g:

os.cp("$(scriptdir)/*.h", "$(buildir)/inc")
os.cp("$(projectdir)/src/test/**.h", "$(buildir)/inc")

The above code will: all the header files in the current xmake.lua directory, the header files in the project source test directory are all copied to the $(buildir) output directory.

Among them $(scriptdir), $(projectdir) These variables are built-in variables of xmake. For details, see the related documentation of built-in variables.

The matching patterns in *.h and **.h are similar to those in add_files, the former is a single-level directory matching, and the latter is a recursive multi-level directory matching.

This interface also supports `recursive replication' of directories, for example:

-- Recursively copy the current directory to a temporary directory
os.cp("$(curdir)/test/", "$(tmpdir)/test")

The copy at the top will expand and copy all files to the specified directory, and lose the source directory hierarchy. If you want to copy according to the directory structure that maintains it, you can set the rootdir parameter:

os.cp("src/**.h", "/tmp/", {rootdir="src"})

The above script can press the root directory of src to copy all sub-files under src in the same directory structure.

âš  Try to use the os.cp interface instead of os.run("cp .."), which will ensure platform consistency and cross-platform build description.

Under 2.5.7, the parameter {symlink = true} is added to keep the symbolic link when copying files.

os.cp("/xxx/foo", "/xxx/bar", {symlink = true})

Introduced in version 2.0.1

See also

os.trycp, os.vcp, os.mv, os.rm, os.ln, os.touch

edit

os.cpuinfo

table os.cpuinfo()

Get cpu information

print(os.cpuinfo())
-- got {
--   ncpu = 8,
--   usagerate = 0.0,
--   model_name = "Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz",
--   march = "Kaby Lake",
--   vendor = "GenuineIntel",
--   model = 158,
--   family = 6
-- }
print(os.cpuinfo("march")) -- got "Kaby Lake"

Introduced in version 2.1.5

See also

os.default_njob

edit

os.curdir

string os.curdir()

Get the current directory path

Consistent with the result of $(curdir), it is just a direct return to return a variable that can be maintained with subsequent strings.

Usage reference: os.tmpdir.

Introduced in version 2.0.1

See also

$(curdir), os.tmpdir

edit

os.date

table os.date(string format, numeric datetime)

See Date and Time.

See also

os.time

edit

os.default_njob

numeric os.default_njob()

Get default number of parallel jobs

print(os.default_njob()) -- got 10

Introduced in version 2.5.8

See also

os.cpuinfo

edit

os.dirs

table os.dirs(string path_pattern[, function callback])

Traverse to get all the directories under the specified directory

Supports pattern matching in add_files, supports recursive and non-recursive mode traversal, and returns a table array. If not, returns an empty array, for example:

-- Recursive traversal to get all subdirectories
for _, dir in ipairs(os.dirs("$(buildir)/inc/**")) do
    print(dir)
end

Introduced in version 2.0.1

See also

os.files, os.filedirs, os.isdir, os.match

edit

os.emptydir

bool os.emptydir(string path)

Check if the specified directory is empty

Returns true is the directory is empty or doesn't exist. Returns false otherwise.

edit

os.exec

nil os.exec(string cmd_format[, ...])

Echo running native shell commands

Similar to the os.run interface, the only difference is that when this interface executes the shell program, it has the output printed in the console, which is used in general debugging. An exception will be raised if an error happens.

os.exec("program --%s=%d --path=$(buildir)", "value", 42)

Introduced in version 2.0.1

See also

os.run, os.runv, os.iorun, os.iorunv, os.execv, os.vexec, os.vexecv, os.isexec, vformat

edit

os.execv

bool, string os.execv(string cmd, table args[, table opt])

Echo running native shell commands with parameter list

Similar to os.exec, just the way to pass parameters is passed through the parameter list, not the string command, for example:

os.execv("echo", {"hello", "xmake!"})

In addition, this interface also supports an optional parameter for passing settings: redirect output, perform environment variable settings, for example:

os.execv("echo", {"hello", "xmake!"}, {stdout = outfile, stderr = errfile, envs = {PATH = "xxx;xx", CFLAGS = "xx"}})

Valid fields for opt are:

Set try to true to return the errors instead of raising them.

local ok, errors = os.execv("echo", {"hello", "xmake!"}, {try = true})

Among them, the stdout and stderr parameters are used to pass redirected output and error output. You can directly pass in the file path or the file object opened by io.open.

After v2.5.1, we also support setting the stdin parameter to support redirecting input files.

!> stdout/stderr/stdin can simultaneously support three types of values: file path, file object, and pipe object.

In addition, if you want to temporarily set and rewrite some environment variables during this execution, you can pass the envs parameter. The environment variable settings inside will replace the existing settings, but will not affect the outer execution environment, only the current command.

We can also get all the current environment variables through the os.getenvs() interface, and then pass in the envs parameter after rewriting some parts.

Introduced in version 2.1.5

See also

os.exec, os.run, os.vexec, os.vexecv, vformat

edit

os.exists

bool os.exists(string path)

Determine if a file or directory exists

Return false if the file or directory does not exist

-- Judging the existence of the directory
if os.exists("$(buildir)") then
    -- ...
end

-- Judging the existence of the file
if os.exists("$(buildir)/libxxx.a") then
    -- ...
end

Introduced in version 2.0.1

See also

os.isfile, os.isdir, os.isexec

edit

os.exit

bool os.exists(string path)

Exit the program

Introduced in version 2.3.1

See also

os.atexit

edit

os.features

table os.features()

Get features

${print}(os.features())
-- got {
--   path_sep = "\",
--   path_envsep = ";"
-- }

Introduced in version 2.3.1

edit

os.filedirs

table os.filedirs(string path_pattern[, function callback])

Traverse to get all files and directories under the specified directory

Supports pattern matching in target.add_files, supports recursive and non-recursive mode traversal, and returns a table array. If not, returns an empty array, for example:

-- Recursive traversal to get all child files and directories
for _, filedir in ipairs(os.filedirs("$(buildir)/**")) do
    print(filedir)
end

Introduced in version 2.0.1

See also

os.files, os.dirs, os.match

edit

os.files

table os.files(string path_pattern[, function callback])

Traverse to get all the files in the specified directory

Supports pattern matching in target.add_files, supports recursive and non-recursive mode traversal, and returns a table array. If not, returns an empty array, for example:

-- Non-recursive traversal to get all child files
for _, filepath in ipairs(os.files("$(buildir)/inc/*.h")) do
    print(filepath)
end

Introduced in version 2.0.1

See also

os.isfile, os.dirs, os.filedirs, os.match

edit

os.filesize

numeric os.filesize(string path)

Get file size

print(os.filesize("/tmp/a"))

Introduced in version 2.1.9

edit

os.fscase

bool os.fscase([string path])

Test if the os has a case sensitive filesystem

Introduced in version 2.1.9

edit

os.getenv

string os.getenv(string envname)

Get system environment variables

print(os.getenv("PATH"))

Introduced in version 2.0.1

See also

os.getenvs, $(env), os.addenv, os.setenv

edit

os.getenvs

table os.getenvs()

Get all current environment variables

local envs = os.getenvs()
--- home directory (on linux)
print(envs["HOME"])

Introduced in version 2.2.6

See also

os.getenv, $(env)

edit

os.getpid

numeric os.getpid()

Get the current process ID

Introduced in version 2.6.5

edit

os.getwinsize

table os.getwinsize()

Get the console window size

local winsize = os.getwinsize()
-- got {
--   width = 120,
--   height = 9001,
-- }

Introduced in version 2.1.4

edit

os.host

string os.host()

Get the operating system of the current host

Consistent with the result of $(host), for example, if I execute xmake on linux x86_64 to build, the return value is: linux

Introduced in version 2.0.1

See also

is_host, $(host), os.subhost

edit

os.iorun

string, string os.iorun(string cmd)

Quietly running native shell commands and getting output

Similar to the os.run interface, the only difference is that after executing the shell program, this interface will get the execution result of the shell program, which is equivalent to redirecting the output.

You can get the contents of stdout, stderr at the same time, for example:

local outdata, errdata = os.iorun("echo hello xmake!")

Introduced in version 2.0.1

See also

os.iorunv, os.exec, os.run

edit

os.iorunv

string, string os.iorunv(string cmd, table args[, table opt])

Run the native shell command quietly and get the output with a list of parameters

Similar to os.iorun, just the way to pass arguments is passed through the argument list, not the string command, for example:

local outdata, errdata = os.iorunv("echo", {"hello", "xmake!"})
local outdata, errdata = os.iorunv("echo", {"hello", "xmake!"}, {envs = {PATH="..."}})

Valid fields for opt are:

Introduced in version 2.1.5

See also

os.iorun, os.exec, os.run

edit

os.is_arch

bool os.is_arch(string arch[, string ...])

Test if a given arch is the current

local is_x86_64_or_arm64 = os.is_arch("x86_64", "arm64")

Introduced in version 2.3.1

See also

os.arch, is_arch

edit

os.is_host

bool os.is_host(string host[, string ...])

Test if a given host is the current

local is_windows_or_linux = os.is_host("windows", "linux")

Introduced in version 2.3.1

See also

os.host, is_host, $(host)

edit

os.is_subarch

bool os.is_subarch(string subarch[, string ...])

Test if a given sub arch is the current

Introduced in version 2.3.1

See also

os.subarch, is_subarch

edit

os.is_subhost

bool os.is_subhost(string subhost[, string ...])

Test if a given sub host is the current

Introduced in version 2.3.1

See also

os.subhost, is_subhost

edit

os.isdir

bool os.isdir(string path)

Determine if it is a directory

Return false if the directory does not exist

if os.isdir("src") then
    -- ...
end

Introduced in version 2.3.1

See also

os.isfile, os.islink, os.isexec, os.exists

edit

os.isexec

bool os.isexec(string path)

Test if a file is executable

if os.isexec("path/to/file.exe") then
    os.run("path/to/file.exe")
end

Introduced in version 2.0.1

See also

os.isfile, is.isdir, os.islink, os.exists

edit

os.isfile

bool os.isfile(string path)

Determine if it is a file

Return false if the file does not exist

if os.isfile("$(buildir)/libxxx.a") then
    -- ...
end

Introduced in version 2.0.1

See also

os.isdir, os.islink, os.isexec, os.exists

edit

os.islink

bool os.islink(string path)

Determine if it is a link

Return false if the link does not exist

if os.islink("/usr/lib/libmythings.so") then
    -- ...
end

Introduced in version 2.0.1

See also

os.isdir, os.isfile, os.isexec, os.exists, os.ln

edit

os.isroot

bool os.isroot()

Test if xmake is running as root

Introduced in version 2.1.9

edit

os.joinenvs

table os.joinenvs(table envs, table oldenvs)

Join environment variables. Similar to os.addenvs but with two envs variable

local envs = {CUSTOM = "a/path"}
local envs2 = {CUSTOM = "some/path/"}
print(os.joinenvs(envs, envs2))

The result is: { CUSTOM = "a/path;some/path/" }

Introduced in version 2.5.6

See also

os.getenv, os.getenvs, os.addenv, os.addenvs

edit

os.ln

nil os.ln(string srcpath, string dstpath[, opt])

Create a symlink to a file or directory

-- creates a symlink file "xxx.txt.ln" which is pointing to "xxx.txt"
os.ln("xxx.txt", "xxx.txt.ln")

Valid field for opt is:

Set force to true if you wish to overwrite the item at dstpath

Introduced in version 2.2.2

See also

os.vln, os.islink, os.cp, os.mv, os.touch

edit

os.match

table, numeric os.match(string pattern[, mode[, function callback]])

match files or directories

The search pattern uses:

Valid values for mode are:

The function returns the items found and count.

local dirs, count = os.match("./src/*", true)
local files, count = os.match("./src/**.c")
local file = os.match("./src/test.c", 'f', function (filepath, isdir)
                 return true   -- continue it
                 return false  -- break it
             end)

Introduced in version 2.0.1

edit

os.mclock

numeric os.mclock()

local time = os.mclock()
os.execv(program)
time = os.mclock() - time
print("time %0.3fs", time / 1000.)

See also

os.time, os.mtime, os.sleep

edit

os.meminfo

table os.meminfo()

local info = os.meminfo()
-- got {
--   availsize = 23124,
--   pagesize = 4096,
--   usagerate = 0.29091410873632,
--   totalsize = 32611
-- }
edit

os.mkdir

nil os.mkdir(string dir)

Create a directory

Support for batch creation and built-in variables, such as:

os.mkdir("$(tmpdir)/test", "$(buildir)/inc")

Introduced in version 2.0.1

See also

os.touch, os.cp, os.mv, os.ln

edit

os.mtime

numeric os.mtime(string path)

Get file modification time

local time = os.mtime("$(buildir)/file.o")

See also

os.time, os.sleep

edit

os.mv

nil os.mv(string src, string dst)

Move to rename a file or directory

Similar to the use of os.cp, it also supports multi-file move operations and pattern matching, for example:

-- Move multiple files to a temporary directory
os.mv("$(buildir)/test1", "$(tmpdir)")

-- File movement does not support bulk operations, which is file renaming
os.mv("$(buildir)/libtest.a", "$(buildir)/libdemo.a")

Introduced in version 2.0.1

See also

os.trymv, os.vmv, os.cp, os.trycp, os.rm, os.ln, os.touch

edit

os.nuldev

string os.nuldev([bool input])

Get the system null device

edit

os.pbcopy

nil os.pbcopy(string data)

Copy string data to pasteboard/clipboard

Currently only implemented for linux and macosx

See also

os.pbpaste

edit

os.pbpaste

string os.pbpaste()

Read string data from pasteboard/clipboard

Currently only implemented for linux and macosx

See also

os.pbcopy

edit

os.programdir

string os.programdir()

Get the xmake installation main program script directory

Consistent with the result of $(programdir), it is just a direct get returned to a variable, which can be maintained with subsequent strings.

Introduced in version 2.1.5

See also

$(programdir)

edit

os.programfile

string os.programfile()

Get the path of the xmake executable

Introduced in version 2.1.5

See also

os.programdir, os.scriptdir

edit

os.projectdir

string os.projectdir()

Get the project home directory

Consistent with the result of $(projectdir), it is just a direct return to return a variable that can be maintained with subsequent strings.

Introduced in version 2.1.5

See also

$(projectdir), os.projectfile

edit

os.projectfile

string os.projectfile()

Get the path to the current project xmake.lua file

See also

os.projectdir

edit

os.raise

nil os.raise(string messageformat[, ...])

Raise an exception and abort the current script

-- Raise exception with message "the error #42 occurred"
os.raise("the error #%d occurred", errcode)

It is recommanded to use the builtin function raise instead of os.raise

Introduced in version 2.2.8

See also

raise, try, catch, finally

edit

os.readlink

Read the content of a symlink

os.touch("xxx.txt")
os.ln("xxx.txt", "xxx.txt.ln")
print(os.readlink("xxx.txt.ln")) -- got "xxx.txt"

Introduced in version 2.2.2

See also

os.ln

edit

os.rm

nil os.rm(string path)

Delete files or directory trees

Support for recursive deletion of directories, bulk delete operations, and pattern matching and built-in variables, such as:

os.rm("$(buildir)/inc/**.h")
os.rm("$(buildir)/lib/")

Introduced in version 2.0.1

See also

os.tryrm, os.vrm, os.rmdir, os.mv, os.cp, os.touch

edit

os.rmdir

nil os.rmdir(string dir)

Delete only the directory

If it is not a directory, it cannot be deleted.

Returns true on success, returns false, errmsg otherwise.

Introduced in version 2.0.1

See also

os.rm

edit

os.run

nil os.run(string cmd_format[, ...])

Quietly running native shell commands

Used to execute third-party shell commands, but will not echo the output, only after the error, highlight the error message.

This interface supports parameter formatting and built-in variables such as:

-- Formatted parameters passed in
os.run("echo hello %s!", "xmake")

-- List build directory files
os.run("ls -l $(buildir)")

Using this interface to execute shell commands can easily reduce the cross-platform build. For os.run("cp .."), try to use os.cp instead.
If you must use this interface to run the shell program, please use the config.plat interface to determine the platform support.

For more advanced process operations and control, see the process module interface.

Introduced in version 2.0.1

See also

os.runv, os.vrun, os.iorun, os.exec, core.base.process

edit

os.runv

nil os.runv(string cmd, table args[, table opt])

Quietly running native shell commands with parameter list

Similar to os.run, just the way to pass parameters is passed through the parameter list, not the string command, for example:

os.runv("echo", {"hello", "xmake!"})

Valid fields for opt are:

Introduced in version 2.1.5

See also

os.run, os.vrunv, os.iorunv, os.execv

edit

os.scriptdir

string os.scriptdir()

Get the path of the current description script

Consistent with the result of $(scriptdir), it is just a direct return to return a variable that can be maintained with subsequent strings.

Usage reference: os.tmpdir.

Introduced in version 2.0.1

See also

$(scriptdir), os.projectfile, os.projectdir

edit

os.setenv

bool os.setenv(string varname, string ...)

Set system environment variables

local ok = os.setenv("HOME", "/tmp/")

Introduced in version 2.0.1

See also

os.setenvp, os.setenvs, os.getenv, os.addenv

edit

os.setenvp

bool os.setenvp(string varname, table values, string separator)

Setting environment variables with a given separator

-- Set 'bin$lib' to PATH
local ok = os.setenvp("PATH", {"bin", "lib"}, '$')

Introduced in version 2.1.5

See also

os.setenv, os.setenvs

edit

os.setenvs

table os.setenvs(table envs)

Set environment variables. Replace the current envs by a new one and return old envs

local envs = {}
envs["PATH"] = "/xxx:/yyy/foo"
local oldenvs = os.setenvs(envs)
-- ...
os.setenvs(oldenvs)

Introduced in version 2.2.6

See also

os.setenv, os.setenvp, os.getenvs

edit

os.shell

Get current shell (pwsh, cmd, ...)

print(os.shell())
-- got pwsh

Introduced in version 2.7.3

See also

$(shell), os.term

edit

os.sleep

nil os.sleep(numeric interval)

interval input value is in milliseconds.

os.sleep(1000)

See also

os.time, os.mclock

edit

os.strerror

string os.strerror()

Get the current internal error as a string

local errors = os.strerror()
-- got Unknown

See also

os.syserror

edit

os.subarch

string os.subarch()

Get Subsystem host architecture

print(os.subarch())
-- got x64

Introduced in version 2.3.1

See also

is_subarch, os.is_subarch, os.arch

edit

os.subhost

string os.subhost()

Get Subsystem host, e.g. msys, cygwin on windows

print(os.subhost())
-- got linux

Introduced in version 2.3.1

See also

os.is_subhost, is_subhost, os.host

edit

os.syserror

numeric os.syserror()

Get the current internal system error

Possible return values are:

local errcode = os.syserror()
-- got -1

See also

os.strerror

edit

os.term

string os.term()

Get current terminal (windows-terminal, vscode, ... )

print(os.term())
-- got xterm

Introduced in version 2.7.3

See also

os.shell

edit

os.time

numeric os.time([table time])

See Date and Time.

See also

os.date

edit

os.tmpdir

string os.tmpdir([table opt])

Get temporary directory

Consistent with the result of $(tmpdir), it is just a direct return to return a variable that can be maintained with subsequent strings.

print(path.join(os.tmpdir(), "file.txt"))

Equivalent to:

print("$(tmpdir)/file.txt")

Valid field for opt is:

Introduced in version 2.0.1

See also

$(tmpdir), os.tmpfile

edit

os.tmpfile

string os.tmpfile(opt_or_key)

Get temporary file path

Used to get a temporary file path, just a path, the file needs to be created by itself.

local tmp1 = os.tmpfile("xxx")
local tmp2 = os.tmpfile({key = "xxx", ramdisk = false})

Valid fields for opt are:

Introduced in version 2.0.1

See also

os.tmpdir

edit

os.touch

nil os.touch(string path[, table opt])

Create an empty file

print(os.isfile("xxx.txt")) -- got false
os.touch("xxx.txt")
print(os.isfile("xxx.txt")) -- got true

Valid field for opt is:

See also

os.cp, os.mv, os.rm

edit

os.trycp

bool os.trycp(string srcpath, string dstpath[, table opt])

Try copying files or directories

Similar to os.cp, the only difference is that this interface operation will not throw an exception interrupt xmake, but the return value indicates whether the execution is successful.

if os.trycp("file", "dest/file") then
end

Valid fields for opt are:

Introduced in version 2.1.6

See also

os.cp, os.tryrm, os.trymv

edit

os.trymv

bool os.trymv(string srcpath, dstpath)

Try moving a file or directory

Similar to os.mv, the only difference is that this interface operation will not throw an exception interrupt xmake, but the return value indicates whether the execution is successful.

if os.trymv("file", "dest/file") then
end

Introduced in version 2.1.6

See also

os.mv, os.trycp, os.tryrm

edit

os.tryrm

bool os.tryrm(string path[, table opt])

Try deleting files or directories

Similar to os.rm, the only difference is that this interface operation will not throw an exception interrupt xmake, but the return value indicates whether the execution is successful.

if os.tryrm("file") then
end

Valid field for opt is:

Set emptydirs to true to also remove empty parent directories of this file path.

Introduced in version 2.1.6

See also

os.rm, os.trycp, os.trymv

edit

os.vcp

nil os.vcp(string srcpath, string dstpath[, table opt])

Copy file or directory and echo the verbose info if [-v|--verbose] option is enabled

The interface is the same as os.cp.

See also

os.cp

edit

os.vexec

nil os.vexec(string cmd_format[, ...])

Execute command and echo verbose info if [-v|--verbose] option is enabled

The interface is the same as os.exec.

See also

os.exec

edit

os.vexecv

bool, string os.vexecv(string cmd, table args[, table opt])

Execute command with arguments list and echo verbose info if [-v|--verbose] option is enabled

The interface is the same as os.execv.

See also

os.execv

edit

os.vln

nil os.vln(string srcpath, string dstpath[, opt])

Link file or directory and echo verbose info if [-v|--verbose] option is enabled

The interface is the same as os.ln.

See also

os.ln

edit

os.vmv

nil os.vmv(string src, string dst)

Move file or directory and echo verbose info if [-v|--verbose] option is enabled

The interface is the same as os.mv.

See also

os.mv

edit

os.vrm

nil os.rm(string path)

Remove file or directory and echo verbose info if [-v|--verbose] option is enabled

The interface is the same as os.rm.

See also

os.rm

edit

os.vrun

nil os.vrun(string cmd_format[, ...])

Quietly run command and echo verbose info if [-v|--verbose] option is enabled

The interface is the same as os.run.

See also

os.run

edit

os.vrunv

nil os.runv(string cmd, table args[, table opt])

Quietly run command with arguments list and echo verbose info if [-v|--verbose] option is enabled

The interface is the same as os.runv.

See also

os.runv

edit

os.workingdir

string os.workingdir()

Get the working directory

Introduced in version 2.1.9

See also

os.curdir, os.cd, os.projectdir

edit

os.xmakever

string os.xmakever()

Get the current xmake version

print(os.xmakever())
-- got 2.7.6
edit
Interfaces
os.addenv
os.addenvp
os.addenvs
os.arch
os.args
os.argv
os.atexit
os.cd
os.cp
os.cpuinfo
os.curdir
os.date
os.default_njob
os.dirs
os.emptydir
os.exec
os.execv
os.exists
os.exit
os.features
os.filedirs
os.files
os.filesize
os.fscase
os.getenv
os.getenvs
os.getpid
os.getwinsize
os.host
os.iorun
os.iorunv
os.is_arch
os.is_host
os.is_subarch
os.is_subhost
os.isdir
os.isexec
os.isfile
os.islink
os.isroot
os.joinenvs
os.ln
os.match
os.mclock
os.meminfo
os.mkdir
os.mtime
os.mv
os.nuldev
os.pbcopy
os.pbpaste
os.programdir
os.programfile
os.projectdir
os.projectfile
os.raise
os.readlink
os.rm
os.rmdir
os.run
os.runv
os.scriptdir
os.setenv
os.setenvp
os.setenvs
os.shell
os.sleep
os.strerror
os.subarch
os.subhost
os.syserror
os.term
os.time
os.tmpdir
os.tmpfile
os.touch
os.trycp
os.trymv
os.tryrm
os.vcp
os.vexec
os.vexecv
os.vln
os.vmv
os.vrm
os.vrun
os.vrunv
os.workingdir
os.xmakever