Skip to content

Add Remove line option #1

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

Closed
MitkoVtori opened this issue Feb 13, 2023 · 1 comment
Closed

Add Remove line option #1

MitkoVtori opened this issue Feb 13, 2023 · 1 comment
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@MitkoVtori
Copy link
Owner

MitkoVtori commented Feb 13, 2023

Add option to remove a single line or a bunch of lines in range from file/table...

@MitkoVtori MitkoVtori self-assigned this Feb 13, 2023
@MitkoVtori MitkoVtori added the documentation Improvements or additions to documentation label Feb 13, 2023
MitkoVtori added a commit that referenced this issue Feb 18, 2023
Added DEL TABLE/FILE LINES command. Fixed (#1, #2)
@MitkoVtori
Copy link
Owner Author

def delete_lines(database, path, file_name, *lines):
'''
Console command
DEL TABLE/FILE FileName LINES firstline secondline seventhline
'''
if path == "table":
if os.path.exists(f"databases/{database}/tables/{file_name}.txt"):
file = [line[:-1] if line[-1] == '\n' else line for line in open(f"databases/{database}/tables/{file_name}.txt", "r")]
for num, line in enumerate(lines):
if 0 <= (line+1)-num < len(file):
file.pop((line+1)-num)
os.remove(f"databases/{database}/tables/{file_name}.txt")
f = open(f"databases/{database}/tables/{file_name}.txt", "a+")
for line in file:
f.write(f"{line}\n")
f.close()
elif path == "file":
if os.path.exists(f"databases/{database}/files/{file_name}.txt"):
file = [line[:-1] if line[-1] == '\n' else line for line in open(f"databases/{database}/files/{file_name}.txt", "r")]
for num, line in enumerate(lines):
if 0 <= (line - 1) - num < len(file):
file.pop((line - 1) - num)
os.remove(f"databases/{database}/files/{file_name}.txt")
f = open(f"databases/{database}/files/{file_name}.txt", "a+")
for line in file:
f.write(f"{line}\n")
f.close()
else:
return Fore.LIGHTWHITE_EX + f"Invalid path name '{path}'"
return Fore.LIGHTWHITE_EX + "lines removed!"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant