Comprobar si existe un archivo usando Batch

MD Aminul Islam 20 marzo 2023
Comprobar si existe un archivo usando Batch

Este artículo demostrará cómo verificar si un archivo existe o no usando un Batch script a través de un código de ejemplo.

Comprobar si existe un archivo mediante un Batch script

El formato general o la sintaxis del código para verificar si existe un archivo se proporciona a continuación.

IF EXIST filename.txt (
    action if file exists
) ELSE (
    action if the file doesn't exist
)

El siguiente ejemplo comprobará si el archivo simple.txt existe o no. Si el archivo existe, mostrará el mensaje File exists!!!; si el archivo no existe, mostrará el mensaje: File missing!!!.

Código de ejemplo:

IF EXIST simple.txt (
    echo File exists!!!
) ELSE (
    echo File missing!!!
)

Producción :

File exists!!!

Recuerde, los métodos discutidos aquí están escritos usando Batch Script y solo funcionan en Windows CMD.

MD Aminul Islam avatar MD Aminul Islam avatar

Aminul Is an Expert Technical Writer and Full-Stack Developer. He has hands-on working experience on numerous Developer Platforms and SAAS startups. He is highly skilled in numerous Programming languages and Frameworks. He can write professional technical articles like Reviews, Programming, Documentation, SOP, User manual, Whitepaper, etc.

LinkedIn

Artículo relacionado - Batch File