Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
c7df9c6c
Commit
c7df9c6c
authored
May 10, 2015
by
Steve Zatz
Committed by
Damien George
May 12, 2015
Browse files
stmhal: Add os.rename function.
parent
f601390e
Changes
3
Hide whitespace changes
Inline
Side-by-side
docs/library/os.rst
View file @
c7df9c6c
...
...
@@ -46,6 +46,10 @@ Functions
Remove a directory.
.. function:: rename(old_path, new_path)
Rename a file.
.. function:: stat(path)
Get the status of a file or directory.
...
...
stmhal/moduos.c
View file @
c7df9c6c
...
...
@@ -239,6 +239,22 @@ STATIC mp_obj_t os_remove(mp_obj_t path_o) {
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
os_remove_obj
,
os_remove
);
/// \function rename(old_path, new_path)
/// Rename a file
STATIC
mp_obj_t
os_rename
(
mp_obj_t
path_in
,
mp_obj_t
path_out
)
{
const
char
*
old_path
=
mp_obj_str_get_str
(
path_in
);
const
char
*
new_path
=
mp_obj_str_get_str
(
path_out
);
FRESULT
res
=
f_rename
(
old_path
,
new_path
);
switch
(
res
)
{
case
FR_OK
:
return
mp_const_none
;
default:
nlr_raise
(
mp_obj_new_exception_msg_varg
(
&
mp_type_OSError
,
"Error renaming file '%s' to '%s'"
,
old_path
,
new_path
));
}
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_2
(
os_rename_obj
,
os_rename
);
/// \function rmdir(path)
/// Remove a directory.
STATIC
mp_obj_t
os_rmdir
(
mp_obj_t
path_o
)
{
...
...
@@ -368,6 +384,7 @@ STATIC const mp_map_elem_t os_module_globals_table[] = {
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_listdir
),
(
mp_obj_t
)
&
os_listdir_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_mkdir
),
(
mp_obj_t
)
&
os_mkdir_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_remove
),
(
mp_obj_t
)
&
os_remove_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_rename
),(
mp_obj_t
)
&
os_rename_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_rmdir
),
(
mp_obj_t
)
&
os_rmdir_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_stat
),
(
mp_obj_t
)
&
os_stat_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_unlink
),
(
mp_obj_t
)
&
os_remove_obj
},
// unlink aliases to remove
...
...
stmhal/qstrdefsport.h
View file @
c7df9c6c
...
...
@@ -379,6 +379,7 @@ Q(chdir)
Q
(
getcwd
)
Q
(
listdir
)
Q
(
mkdir
)
Q
(
rename
)
Q
(
remove
)
Q
(
rmdir
)
Q
(
unlink
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment