Вопрос задан 29.08.2018 в 22:41. Предмет Информатика. Спрашивает Гришанова Анастасия.

Создать командный файл, который бы выводил на экран все файлы заданного расширения. Если расширение

при вызове командного файла не заданно вывести: "Расширение не введено", если в текущем каталоге файлов с таким расширением нет, то вывести: "Файлов не найдено".
0 0
Перейти к ответам

Ответы на вопрос

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Мисюрева Настя.
@echo off
SET EXT=%1
IF "%EXT%"=="" (ECHO Расширение не введено) ELSE (
WHERE /Q "*.%EXT%"
IF ERRORLEVEL 1 (ECHO Файлов не найдено) ELSE WHERE *.%EXT%
)

0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Creating a Command File to Display Files of a Specific Extension

To create a command file that displays all files of a specified extension, you can use a scripting language like Batch or PowerShell. Here's an example using Batch scripting:

1. Open a text editor and create a new file. 2. Save the file with a `.bat` extension, for example, `display_files.bat`.

The content of the `display_files.bat` file should be as follows:

```batch @echo off setlocal

REM Check if the extension is provided as an argument if "%~1"=="" ( echo "Extension not entered" exit /b )

REM Check if files with the specified extension exist in the current directory dir /b /a-d *.%~1 >nul 2>nul if errorlevel 1 ( echo "No files found" ) else ( dir /b /a-d *.%~1 )

endlocal ```

Let's break down the script:

- The `@echo off` command turns off the display of commands in the command prompt. - The `setlocal` command creates a local scope for variables. - The script checks if the extension is provided as an argument. If not, it displays the message "Extension not entered" and exits. - The `dir` command is used to list all files (`/a-d` excludes directories) with the specified extension (`*.%~1`) in the current directory. - If no files are found, it displays the message "No files found." - The `endlocal` command ends the local scope for variables.

To use the command file, follow these steps:

1. Open the command prompt. 2. Navigate to the directory where the `display_files.bat` file is saved. 3. Run the command file by entering its name followed by the desired file extension. For example, to display all `.txt` files, enter `display_files.bat txt`.

The command file will then display all files with the specified extension in the current directory. If no files are found, it will display the message "No files found."

Please note that the above example uses Batch scripting. If you prefer using PowerShell, a similar approach can be taken using PowerShell commands.

I hope this helps! Let me know if you have any further questions.

0 0

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос