Batch를 사용하여 파일이 존재하는지 확인

MD Aminul Islam 2023년3월20일
Batch를 사용하여 파일이 존재하는지 확인

이 기사에서는 예제 코드를 통해 Batch 스크립트를 사용하여 파일이 존재하는지 여부를 확인하는 방법을 설명합니다.

배치 스크립트를 사용하여 파일이 존재하는지 확인

파일이 있는지 확인하는 코드의 일반적인 형식 또는 구문은 다음과 같습니다.

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

아래 예제는 simple.txt 파일이 존재하는지 여부를 확인합니다. 파일이 존재하면 File exists!!!라는 메시지가 표시됩니다. 파일이 존재하지 않으면 File missing!!! 메시지가 표시됩니다.

예제 코드:

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

출력:

File exists!!!

여기에서 설명하는 방법은 배치 스크립트를 사용하여 작성되었으며 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

관련 문장 - Batch File