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 28-04-2009
Member
 
Join Date: Dec 2008
Posts: 50
idea Need a Batch script to check files

Hey Guys,

I would like to know that which is the best Batch script for checking files. I would like to have a batch script for the following.

1) If say there is a folder A, in which there are 10 files which are updated daily. I would like to check this files and if the files are updated with latest timestamp.
2) If any of the file is been not updated, then it should be show a display error, saying this file is not been updated.
3) And on destination, before copying i need to have archive existing files.

Is it possible for me to do so? Can any body provide me the correct logical steps for doing it? Any kind of information on the above issue would be appreciated.

Thanks.
Reply With Quote
  #2  
Old 28-04-2009
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: Need a Batch script to check files

OK file exists bit is easy:

Quote:
@echo off
if exists "c:\dir\yourfile.txt" echo It exists
if not exists "c:\dir\yourfile.txt" echo It doesn't exist

To get number of files is slightly more difficult:

@echo off
for /f "tokens=1 delims= " %%a in ('dir ^| find "File(s)"') do echo %%a

You can check that with

@echo off
set numfiles=0
for /f "tokens=1 delims= " %%a in ('dir ^| find "File(s)"') do set numfiles=%%a
if %numfiles% LSS 30 echo Less than 30 files

hth
Reply With Quote
  #3  
Old 28-04-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: Need a Batch script to check files

You did not mention which timestamp - last modification time, last acces time or last creation time. I will assume last modification time.

Here is the script. It is written in biterscripting. It will copy files modified after a certain time stamp from folder A to B.

Quote:
# Get a list of all files whose time stamp is after 20090418.
var str filelist ; find -n "*" "folder A" ($fmtime > "20090418") > $filelist
while ($filelist <> "")
do
# Get the next file.
var str file ; lex "1" $filelist > $file
# Copy file to folder B.
system copy $file "folder B"
done
The above script will copy all files modified after Apr 18, 2009.

Copy the above script into file C:/X.txt. Start biterscripting and call the script as follows.
Quote:
script "C:/X.txt"
That's it.
Reply With Quote
  #4  
Old 28-04-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: Need a Batch script to check files

OK, this is slightly more difficult. Variables are passed into a batch file as command line parameters. An example of this would be the following:
Quote:
Code for making a 'new' copy batch file - Filename: c:\copier.bat

@ECHO OFF
COPY %1 %2
This would be used as follows:

copier testfile.txt c:\folder

This would, in the same way as copy does, copy the file from c:\ to c:\folder\ by calling copy to do it. Not very helpful yet, but you can use this a bit better with a nested batch file.

File 1: test1.bat
Quote:
@ECHO OFF
CALL test2.bat file.txt
ECHO.
ECHO The code here has now run
File2: test2.bat
Quote:
@ECHO OFF
IF EXIST %1 (
DEL %1
) ELSE (
ECHO.
ECHO File does not exist
ECHO.
)
This would check to see if the file stored in batch file 1 exists, then if it does, deletes it, otherwise lets you know. After that, it returns to the first batch file where it left off. If you left out the CALL command it would go and run the second file then immediately terminate without returning.

If you know BASIC, it equates to the CALL command is being a GOSUB with the end of the next file being a RETURN, whereas just the filename is a GOTO.

Hope so it may help you out.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Need a Batch script to check files"
Thread Thread Starter Forum Replies Last Post
Batch Script Issue spmaguire Software Development 3 04-09-2013 10:41 AM
Batch Script to Convert PNG to XPM BRIGHID Operating Systems 3 22-08-2010 03:25 AM
SharePoint Batch Check RICO12 Windows Software 4 06-01-2010 02:59 AM
Need a batch script to map drive Common Networking & Security 3 06-07-2009 07:42 PM
Several. Msc window from a batch / script call? Stephanatic Technology & Internet 2 26-11-2008 05:26 PM


All times are GMT +5.5. The time now is 02:43 AM.