-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Command Line Argument #301
Open
GhalibFaruqe101
wants to merge
2
commits into
ndleah:main
Choose a base branch
from
GhalibFaruqe101:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,55 @@ | ||||
import os | ||||
import argparse | ||||
def open_file(): | ||||
try: | ||||
file_path = input("Enter the path to the file: ") | ||||
os.startfile(file_path) | ||||
except Exception as e: | ||||
print(f"Error opening file: {e}") | ||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def create_folder(): | ||||
folder_path = input("Enter the path to the folder: ") | ||||
folder_name = input("Enter the name of the folder: ") | ||||
try: | ||||
os.makedirs(os.path.join(folder_path, folder_name), exist_ok=True) | ||||
print(f"Folder '{folder_name}' created successfully.") | ||||
except Exception as e: | ||||
print(f"Error creating folder: {e}") | ||||
|
||||
|
||||
def write_to_file(): | ||||
file_path = input("Enter the name of the file: ") | ||||
file_name = os.path.basename(file_path) | ||||
try: | ||||
with open(file_path, 'w') as f: | ||||
f.write(input("Enter the text to be written to the file: ")) | ||||
print(f"File '{file_name}' created successfully.") | ||||
except Exception as e: | ||||
print(f"Error writing to file: {e}") | ||||
|
||||
|
||||
def main(): | ||||
|
||||
parseer = argparse.ArgumentParser(description="Command Line Argumet") | ||||
parseer.add_argument("-w", "--write", help="write to a file", action="store_true") | ||||
parseer.add_argument("-o", "--open", help="open a file", action="store_true") | ||||
parseer.add_argument("-c", "--create", help="create a new folder", action="store_true") | ||||
GhalibFaruqe101 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
args = parseer.parse_args() | ||||
if args.write: | ||||
write_to_file() | ||||
elif args.open: | ||||
open_file() | ||||
elif args.create: | ||||
create_folder() | ||||
|
||||
|
||||
Comment on lines
+49
to
+50
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.
Suggested change
|
||||
else: | ||||
print("Invalid input. Please try again.") | ||||
|
||||
if __name__== "__main__": | ||||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# File Management Tool | ||
|
||
A simple command-line tool for managing files and folders in Python. This tool allows users to create folders, open files, and write content to files through command-line arguments. | ||
|
||
## Features | ||
|
||
- **Open a File**: Opens a specified file using the default application. | ||
- **Create a Folder**: Creates a new folder at a specified location. | ||
- **Write to a File**: Creates a new file or overwrites an existing one with user-provided text. | ||
|
||
## Requirements | ||
|
||
- Python 3.x | ||
- os | ||
- argparse | ||
|
||
## Usage | ||
|
||
### Command Line Arguments | ||
|
||
You can use the following command-line arguments to execute different functionalities: | ||
|
||
- `-o` or `--open`: Opens a specified file. | ||
- `-c` or `--create`: Creates a new folder. | ||
- `-w` or `--write`: Writes to a specified file. | ||
|
||
### Examples | ||
|
||
1. **To Open a File:** | ||
```bash | ||
name_of_the_file -o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Yeah!! |
Binary file removed
BIN
-261 KB
NASA_Image_Extraction/Astro_Images/2022-11-25_NGC 6744: Extragalactic Close-Up.mp3
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.