Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Bat File - Check if folder exists  (Read 20497 times)

0 Members and 1 Guest are viewing this topic.

Slopeshunter

  • Guest
Bat File - Check if folder exists
« on: March 22, 2007, 08:14:08 AM »
Hello everyone,

I am trying to write a batch file that will do the following check:

If the following folder exists (H:\Data\Time Tracker in this case) then
   Copy a file to H:\Data\Time Tracker
Else
   Copy a file to C:\Programs\Time Tracker

Any pointers would be appreciated. This has got me stumped.

Thanks in advance!

lordoftheplat



    Hopeful

  • teh god.
  • Thanked: 1
    Re: Bat File - Check if folder exists
    « Reply #1 on: March 22, 2007, 08:16:35 AM »
    quite confusing wad u are saying can u list wad the file type is
    zepperblood.deviantart.com

    Slopeshunter

    • Guest
    Re: Bat File - Check if folder exists
    « Reply #2 on: March 22, 2007, 08:20:49 AM »
    I guess I could check for a file if that's easier than a folder.

    Basically I'm trying to update one file for a number of different users. The file is an executable and can be located in one of two places (either C:\Programs\Time Tracker OR H:\Data\Time Tracker).

    That's why when the user double clicks the bat file I need to first check where the exe file is currently located so that it can be updated with a newer copy of the exe file.

    Thanks.

    lordoftheplat



      Hopeful

    • teh god.
    • Thanked: 1
      Re: Bat File - Check if folder exists
      « Reply #3 on: March 22, 2007, 08:29:43 AM »
      well u can do this

      @echo off
      echo.
      xcopy C:\Programs\Time Tracker.exe H:\Data\Time Tracker.exe

      this copies it from C: to H:
      zepperblood.deviantart.com

      lordoftheplat



        Hopeful

      • teh god.
      • Thanked: 1
        Re: Bat File - Check if folder exists
        « Reply #4 on: March 22, 2007, 08:39:08 AM »
        btw i think u can do this

        dir /s C:\...\time tracker.exe


        that should find the time tracker.exe's directory
        « Last Edit: March 22, 2007, 08:40:07 AM by lordoftheplat »
        zepperblood.deviantart.com

        Slopeshunter

        • Guest
        Re: Bat File - Check if folder exists
        « Reply #5 on: March 22, 2007, 08:39:52 AM »
        Sorry, I guess I wasn't quite getting my question correct.

        This bat file will be run by a number of different users from their PC's. The purpose of the bat file is to update the file ProjectTimeTracker.exe to a newer version.

        On each user's PC the file ProjectTimeTracker.exe is either located on their C drive (C:\Programs\Time Tracker\) or their H drive (H:\Data\Time Tracker\). That is why the first thing the batch file needs to do is to find out where the file currently resides for the user (C drive or H drive), then once the current location is known the executable file can be updated to that location.

        Thanks for your help!

        lordoftheplat



          Hopeful

        • teh god.
        • Thanked: 1
          Re: Bat File - Check if folder exists
          « Reply #6 on: March 22, 2007, 08:40:42 AM »
          Quote
          btw i think u can do this

          dir /s C:\...\time tracker.exe


          that should find the time tracker.exe's directory

          or
          dir /s H:\...\time tracker.exe


          so added together


          @echo off
          echo.
          dir /s C:\...\time tracker.exe
          dir /s H:\...\time tracker.exe
          « Last Edit: March 22, 2007, 08:41:27 AM by lordoftheplat »
          zepperblood.deviantart.com

          ghostdog74



            Specialist

            Thanked: 27
            Re: Bat File - Check if folder exists
            « Reply #7 on: March 22, 2007, 08:44:40 AM »
            Quote
            Hello everyone,

            I am trying to write a batch file that will do the following check:

            If the following folder exists (H:\Data\Time Tracker in this case) then
               Copy a file to H:\Data\Time Tracker
            Else
               Copy a file to C:\Programs\Time Tracker

            Any pointers would be appreciated. This has got me stumped.

            Thanks in advance!

            using the command prompt, type if /?. you will find help to check existence of a folder

            eg

            Code: [Select]
            if exist "your H drive path" (
             copy "file" "your H drive path"
            ) else (
            copy "file" "your C drive path"
            )

            « Last Edit: March 22, 2007, 08:45:28 AM by ghostdog74 »

            Slopeshunter

            • Guest
            Re: Bat File - Check if folder exists
            « Reply #8 on: March 22, 2007, 09:14:02 AM »
            Thanks for your help, I was able to get it working by modifing the code sample you supplied. :)

            WillyW



              Specialist
            • Thanked: 29
            • Experience: Experienced
            • OS: Windows XP
            Re: Bat File - Check if folder exists
            « Reply #9 on: March 22, 2007, 09:19:35 AM »
            Quote
            Hello everyone,

            I am trying to write a batch file that will do the following check:

            If the following folder exists (H:\Data\Time Tracker in this case) then
               Copy a file to H:\Data\Time Tracker
            Else
               Copy a file to C:\Programs\Time Tracker

            Any pointers would be appreciated. This has got me stumped.

            Thanks in advance!


            See out this thread:
            http://www.computerhope.com/cgi-bin/yabb/YaBB.cgi?num=1173588211/2#2

            Checking for the existence of a directory,  then performing some action if it exists or not,   is discussed.    An example is there too.

            I hope this helps.


            .