Exemple #1
0
tb_bool_t tb_directory_copy(tb_char_t const* path, tb_char_t const* dest)
{
    // the absolute path
    tb_char_t full0[TB_PATH_MAXN];
    path = tb_path_absolute(path, full0, TB_PATH_MAXN);
    tb_assert_and_check_return_val(path, tb_false);

    // the dest path
    tb_char_t full1[TB_PATH_MAXN];
    dest = tb_path_absolute(dest, full1, TB_PATH_MAXN);
    tb_assert_and_check_return_val(dest, tb_false);

    // walk copy
    tb_value_t tuple[3];
    tuple[0].cstr = dest;
    tuple[1].ul = tb_strlen(path);
    tuple[2].b = tb_true;
    tb_directory_walk(path, -1, tb_true, tb_directory_walk_copy, tuple);

    // ok?
    tb_bool_t ok = tuple[2].b;

    // copy empty directory?
    if (ok && !tb_file_info(dest, tb_null)) 
        return tb_directory_create(dest);

    // ok?
    return ok;
}
Exemple #2
0
/* //////////////////////////////////////////////////////////////////////////////////////
 * main
 */ 
tb_int_t tb_demo_platform_directory_main(tb_int_t argc, tb_char_t** argv)
{
#if 1
    // home
    tb_char_t home[TB_PATH_MAXN] = {0};
    if (tb_directory_home(home, sizeof(home))) tb_trace_i("home: %s", home);

    // current
    tb_char_t current[TB_PATH_MAXN] = {0};
    if (tb_directory_current(current, sizeof(current))) tb_trace_i("current: %s", current);

    // temporary
    tb_char_t temporary[TB_PATH_MAXN] = {0};
    if (tb_directory_temporary(temporary, sizeof(temporary))) tb_trace_i("temporary: %s", temporary);
#elif 0

    // current
    tb_char_t current[TB_PATH_MAXN] = {0};
    if (tb_directory_current(current, sizeof(current))) tb_trace_i("current: %s", current);

    // current
    tb_directory_walk(argv[1]? argv[1] : current, tb_true, tb_true, tb_directory_walk_func, tb_null);
#elif 0
    tb_directory_remove(argv[1]);
#else
//  tb_directory_walk(argv[1], tb_true, tb_true, tb_directory_walk_func, tb_null);
    tb_directory_copy(argv[1], argv[2]);
#endif

    return 0;
}
Exemple #3
0
/* //////////////////////////////////////////////////////////////////////////////////////
 * implementation
 */
tb_int_t xm_os_emptydir(lua_State* lua)
{
    // check
    tb_assert_and_check_return_val(lua, 0);

    // get the directory
    tb_char_t const* dir = luaL_checkstring(lua, 1);
    tb_check_return_val(dir, 0);

    // done os.emptydir(dir) 
    tb_bool_t is_emptydir = tb_true;
    tb_directory_walk(dir, tb_false, tb_true, xm_os_emptydir_walk, &is_emptydir);

    // is emptydir?
    lua_pushboolean(lua, is_emptydir);

    // ok
    return 1;
}
Exemple #4
0
/* //////////////////////////////////////////////////////////////////////////////////////
 * implementation
 */
tb_int_t xm_os_find(lua_State* lua)
{
    // check
    tb_assert_and_check_return_val(lua, 0);

    // get the root directory
    tb_char_t const* rootdir = luaL_checkstring(lua, 1);
    tb_check_return_val(rootdir, 0);

    // get the pattern
    tb_char_t const* pattern = luaL_checkstring(lua, 2);
    tb_check_return_val(pattern, 0);

    // is recurse?
    tb_bool_t recurse = lua_toboolean(lua, 3);

    // find directory?
    tb_bool_t findir = lua_toboolean(lua, 4);

    // init table
    lua_newtable(lua);

    // get string package    
    lua_getglobal(lua, "string");

    // done os.find(root, name) 
    tb_value_t tuple[4];
    tuple[0].ptr    = lua;
    tuple[1].cstr   = pattern;
    tuple[2].b      = findir;
    tuple[3].ul     = 0;
    tb_directory_walk(rootdir, recurse, tb_true, xm_os_find_walk, tuple);

    // pop string package
    lua_pop(lua, 1);

    // return count
    lua_pushinteger(lua, tuple[3].ul);

    // ok
    return 2;
}
Exemple #5
0
tb_bool_t tb_directory_copy(tb_char_t const* path, tb_char_t const* dest)
{
    // the full path
    tb_char_t full0[TB_PATH_MAXN];
    path = tb_path_full(path, full0, TB_PATH_MAXN);
    tb_assert_and_check_return_val(path, tb_false);

    // the dest path
    tb_char_t full1[TB_PATH_MAXN];
    dest = tb_path_full(dest, full1, TB_PATH_MAXN);
    tb_assert_and_check_return_val(dest, tb_false);

    // walk copy
    tb_value_t tuple[3];
    tuple[0].cstr = dest;
    tuple[1].ul = tb_strlen(path);
    tuple[2].b = tb_true;
    tb_directory_walk(path, tb_true, tb_true, tb_directory_walk_copy, tuple);

    // ok?
    return tuple[2].b;
}