Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 858427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:32:34+00:00 2026-05-15T08:32:34+00:00

I have to create a .BAT file that does this: If C:\myprogram\sync\data.handler exists, exit;

  • 0

I have to create a .BAT file that does this:

  1. If C:\myprogram\sync\data.handler exists, exit;
  2. If C:\myprogram\html\data.sql does not exist, exit;
  3. In C:\myprogram\sync\ delete all files and folders except (test, test3 and test2)
  4. Copy C:\myprogram\html\data.sql to C:\myprogram\sync\
  5. Call other batch file with option sync.bat myprogram.ini.

If it was in the Bash environment it was easy for me, but I do not know how to test if a file or folder exists and if it is a file or folder.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T08:32:34+00:00Added an answer on May 15, 2026 at 8:32 am

    You can use IF EXIST to check for a file:

    IF EXIST "filename" (
      REM Do one thing
    ) ELSE (
      REM Do another thing
    )
    

    If you do not need an "else", you can do something like this:

    set __myVariable=
    IF EXIST "C:\folder with space\myfile.txt" set __myVariable=C:\folder with space\myfile.txt
    IF EXIST "C:\some other folder with space\myfile.txt" set __myVariable=C:\some other folder with space\myfile.txt
    set __myVariable=
    

    Here’s a working example of searching for a file or a folder:

    REM setup
    
    echo "some text" > filename
    mkdir "foldername"
    
    REM finds file   
    
    REM "The ELSE clause must occur on the same line
    as the command after the IF"
    
    IF EXIST "filename" (
      ECHO file filename exists
    ) ELSE (
      ECHO file filename does not exist
    )
    
    REM does not find file
    
    IF EXIST "filename2.txt" (
      ECHO file filename2.txt exists
    ) ELSE (
      ECHO file filename2.txt does not exist
    )
    
    REM folders must have a trailing backslash    
      
    REM finds folder
    
    IF EXIST "foldername\" (
      ECHO folder foldername exists
    ) ELSE (
      ECHO folder foldername does not exist
    )
    
    REM does not find folder
    
    IF EXIST "filename\" (
      ECHO folder filename exists
    ) ELSE (
      ECHO folder filename does not exist
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have create a vcf file that contains contacts by using this code ContentResolver
i have a batch(backup.bat)file.in that i have written a command to create a backup
So I have been writing to Environment.SpecialFolder.ApplicationData this data file, that upon uninstall needs
I have create my own NSOpenGLView class, right now the data that i want
I have the need to run a .bat file to run a SQL command
I have created a .bat file that displays all the users logged in Windows
I have created a .bat file that displays a servers terminal Service SessionID and
I am trying to create a .bat file that starts the ASP.NET Dev Server
I have a batch file that creates a scheduled task using schtasks like this:
I have a given file. I need to create a folder that has 27

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.