Results 1 to 6 of 6

Thread: Batch file to check directory

  1. #1
    Join Date
    Mar 2010
    Posts
    182

    Batch file to check directory

    Hello,
    I am trying to write a batch file which can check if the folder exists. I have tried this but non of the scripts work for me. Also, if the folder does not exist then it should report it in a file that is it should be saved in the file. In short it should be stored in the log file. If you guys have any idea of how to do this then please let me know. Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    359

    Re: Batch file to check directory

    Hello,
    I had written a code in the excel that is a excel file, it detects and saves the files and folders in the desired location, but the problem with the at cod is if the folder does not exists then it gives me an error. Also, the stored data is in saved in the excel file, so , it becomes easy for further manipulation. I have a code which might interest you. This is to check if the folder exists or not
    here is the code
    Code:
    if exist folder\. command
    If I am not wrong then each directory has and .directory extension, so you can test it

  3. #3
    Join Date
    Nov 2009
    Posts
    335

    Re: Batch file to check directory

    Hello,
    You can try the following script and see if this works for you
    Here is the code for the same
    Code:
    @echo off
    if exist "C:\test.ini" (
    echo. File Exists
    pause
    exit
    ) else (
    echo Random Text >>"C:\test.ini"
    exit
    )

  4. #4
    Join Date
    Nov 2009
    Posts
    518

    Re: Batch file to check directory

    Hello,
    Check out the following script
    Code:
    @echo off
    if "%1"=="GoTo:" %1%2
    set err=
    set dir$=%dcmd%
    set dcmd=
    :: Put the necessary files below,
    :: with their sizes
    call %0 GoTo: check file1.dat 1024
    call %0 GoTo: check file2.dat 2048
    call %0 GoTo: check file3.dat 512
    set dcmd=%dir$%
    set dir$=
    if "%err%"=="" goto ok
    set err=
    echo Error: one or more files is
    echo missing or corrupted.
    goto eof
    :check
    dir .\ENHANCE\%3 |FIND "%4"> nul
    if errorlevel=1 set err=1
    goto eof
    :ok
    :: Here goes the main batch
    :eof

  5. #5
    Join Date
    Nov 2009
    Posts
    446

    Re: Batch file to check directory

    Hello,
    I think you want a code that can search in the entire drive for the specified directory. Have you though of the batch files location, if the batch file is in the specific directory then will it check the directory of itself. I guess you have understood what I am trying to say here.
    See Below
    Code:
    if exist "DIRECTORY B\NUL" echo Folder exists!
    If you are trying to use something like this in your code, then it will only check of the the current directory and not all the directories, you have to implement another logic to check it for all the directories.

  6. #6
    Join Date
    Nov 2009
    Posts
    333

    Re: Batch file to check directory

    Hello,
    The above code is been modified for better performance, please take a look at it
    Code:
    @echo off
    if "%1"=="GoTo:" %1%2
    set err=
    set dir$=%dcmd%
    set dcmd=
    :: Put the necessary files below,
    :: with their sizes
    call %0 GoTo: check file1.dat 1.024
    call %0 GoTo: check file2.dat 2.048
    call %0 GoTo: check file3.dat 512
    set dcmd=%dir$%
    set dir$=
    if "%err%"=="" goto ok
    set err=
    echo Error: one or more files is
    echo missing or corrupted.
    goto eof
    :check
    dir .\ENHANCE\%3 |FIND "%4"> nul
    if errlevel=1 set err=1
    goto eof
    :ok
    :: Here goes the main batch
    :eof

Similar Threads

  1. Windows Batch file to output directory names and size to txt file
    By m2thearkus in forum Software Development
    Replies: 6
    Last Post: 16-07-2010, 12:04 AM
  2. How to check if file exists in directory with Php
    By Zool in forum Software Development
    Replies: 3
    Last Post: 03-11-2009, 12:36 PM
  3. Replies: 2
    Last Post: 26-05-2009, 10:41 AM
  4. Can We check the exit command in the batch file
    By Dhruv in forum Software Development
    Replies: 3
    Last Post: 30-12-2008, 11:56 PM
  5. Batch file to create directory with a date in Windows 2003
    By Aadimoolan in forum Window 2000 Help
    Replies: 2
    Last Post: 16-11-2007, 02:55 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,656,946,826.97522 seconds with 17 queries