-
Notifications
You must be signed in to change notification settings - Fork 823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solution #789
base: master
Are you sure you want to change the base?
Solution #789
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,22 @@ | ||
# write your code here | ||
import os | ||
|
||
|
||
def move_file(command: str) -> None: | ||
file_name = command.split()[1] | ||
new_path = command.split()[2] | ||
path_list = new_path.split("/") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using a more descriptive variable name instead of |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of splitting the path manually, use |
||
if command.split()[0] == "mv": | ||
if len(path_list) > 1: | ||
new_dir = os.path.dirname(new_path) | ||
if not os.path.exists(new_dir): | ||
os.makedirs(new_dir) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Be cautious when using |
||
with ( | ||
open(file_name, "r") as file_out, | ||
open(new_path, "w") as file_in | ||
): | ||
file_in.write(file_out.read()) | ||
|
||
if os.path.exists(file_name): | ||
os.remove(file_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a more descriptive variable name instead of
file_name
to better convey its purpose, as per the checklist item: 'Use descriptive and correct variable names.'