Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


File Management Menu filter_list
Author
Message
File Management Menu #1
@echo off

:menu
cls
echo File Management Menu
echo 1. List files in current directory
echo 2. Copy a file
echo 3. Delete a file
echo 4. Exit

set /p choice=Enter your choice:

if "%choice%"=="1" (
dir
) else if "%choice%"=="2" (
set /p sourceFile=Enter source file:
set /p destinationFolder=Enter destination folder:
copy "%sourceFile%" "%destinationFolder%"
) else if "%choice%"=="3" (
set /p fileToDelete=Enter file to delete:
del "%fileToDelete%"
) else if "%choice%"=="4" (
echo Exiting...
exit
) else (
echo Invalid choice. Please try again.
)

pause
goto menu

Explanation:

The script displays a menu with options to list files, copy a file, delete a file, or exit.
It uses conditional statements (if and else) based on the user's choice.
dir: Lists files in the current directory.
copy "%sourceFile%" "%destinationFolder%": Copies a specified file to a specified destination.
del "%fileToDelete%": Deletes a specified file.
The script loops back to the menu after each operation until the user chooses to exit.

This example demonstrates how to create a simple interactive menu system for file management using Batch scripting. Keep in mind that Batch may not be the ideal choice for complex applications, and other scripting languages like PowerShell or Python might be more suitable for advanced tasks.

Reply







Users browsing this thread: 1 Guest(s)