Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 01-04-2010
Member
 
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.
Reply With Quote
  #2  
Old 01-04-2010
Member
 
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
Reply With Quote
  #3  
Old 01-04-2010
Member
 
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
)
Reply With Quote
  #4  
Old 01-04-2010
Member
 
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
Reply With Quote
  #5  
Old 01-04-2010
Member
 
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.
Reply With Quote
  #6  
Old 01-04-2010
Member
 
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Batch file to check directory"
Thread Thread Starter Forum Replies Last Post
Windows Batch file to output directory names and size to txt file m2thearkus Software Development 6 16-07-2010 12:04 AM
How to check if file exists in directory with Php Zool Software Development 3 03-11-2009 12:36 PM
Is it possible to right click on cmd batch file and try to open it in a directory Kamran Operating Systems 2 26-05-2009 10:41 AM
Can We check the exit command in the batch file Dhruv Software Development 3 30-12-2008 11:56 PM
Batch file to create directory with a date in Windows 2003 Aadimoolan Window 2000 Help 2 16-11-2007 02:55 AM


All times are GMT +5.5. The time now is 07:33 AM.