There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
audio avg avg 8 bios boot browser bsod computer cpu crash css dell desktop driver dvd email error excel explorer firefox firefox 3 freeze game graphics hard drive hardware help please hijackthis hjt install internet internet explorer itunes javascript lan laptop malware missing monitor msn network networking openoffice outlook outlook 2003 outlook express php popups problem problems router seo slow sound sp3 spyware startup trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless word
DOS/PDA/Other
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Operating Systems > DOS/PDA/Other >
batch files


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
mdmini's Avatar
Junior Member with 1 posts.
 
Join Date: Apr 2008
Experience: Intermediate
29-Apr-2008, 06:58 AM #1
batch files
hi guys
i wanted to write a batch file that would compare 2 folders and give me the difference in another folder.
i got this script but i want the difference to go to a another folder. plsssssssssssss help....
this is the script i managed to get.......

@echo off


setlocal ENABLEDELAYEDEXPANSION
::Set dirA=%1
::Set dirB=%2

Set dirA=C:\1
Set dirB=C:\2

dir /B /O %dirA% >dirA.txt
dir /B /O %dirB% >dirB.txt


Echo Files that are found in BOTH folders %dirA% AND %dirB% >both.txt
Echo. >>both.txt
findstr /G:dirA.txt dirB.txt >>both.txt
echo ------------------------------------- >>both.txt

Echo Files that are found in folder %dirA% but NOT in folder %dirB% >AnotinB.txt
Echo. >>AnotinB.txt
find /V /C "this_is_an_absurd_string" dirB.txt >numlines.txt
for /f "tokens=3 delims= " %%B in (numlines.txt) do set /A maxnum=%%B

for /F "tokens=* delims= " %%A in (dirA.txt) do (
find /V /C "%%A" dirB.txt >numlines.txt
for /f "tokens=3 delims= " %%B in (numlines.txt) do set /A foundnum=%%B
if %maxnum%==!foundnum! (echo %%A >>AnotinB.txt
xcopy %%A c:\3)

)
echo ------------------------------------- >>AnotinB.txt


Echo Files that are found in folder %dirB% but NOT in folder %dirA% >BnotinA.txt
Echo. >>BnotinA.txt
find /V /C "this_is_an_absurd_string" dirA.txt >numlines.txt
for /f "tokens=3 delims= " %%B in (numlines.txt) do set /A maxnum=%%B

for /F "tokens=* delims= " %%A in (dirB.txt) do (
find /V /C "%%A" dirA.txt >numlines.txt
for /f "tokens=3 delims= " %%B in (numlines.txt) do set /A foundnum=%%B
if %maxnum%==!foundnum! (echo %%A >>BnotinA.txt
copy c:\2 /f C:\3)
)
echo. >>BnotinA.txt
echo ------------------------------------- >>BnotinA.txt

copy /B both.txt+AnotinB.txt+BnotinA.txt dupli.txt >nul
more dupli.txt

for %%A in (dirA.txt dirB.txt both.txt AnotinB.txt BnotinA.txt numlines.txt) do (
if exist %%A del %%A
)
JohnWill's Avatar
Computer Specs
Moderator with 75,246 posts.
 
Join Date: Oct 2002
Location: South Eastern PA, USA
Experience: Advanced age & experience
29-Apr-2008, 09:29 AM #2
Why not just one of the many available utilities to compare the files? This seems to be the hard way!
devil_himself's Avatar
Distinguished Member with 4,779 posts.
 
Join Date: Apr 2007
Location: India
Experience: Advanced
29-Apr-2008, 09:05 PM #3
>>>i got this script but i want the difference to go to a another folder

Change The Location While Outputting It To The Text File

Echo Files that are found in BOTH folders %dirA% AND %dirB% >both.txt
Echo. >>both.txt
findstr /G:dirA.txt dirB.txt >>both.txt
echo ------------------------------------- >>both.txt

Echo Files that are found in folder %dirA% but NOT in folder %dirB% >AnotinB.txt
Echo. >>AnotinB.txt
find /V /C "this_is_an_absurd_string" dirB.txt >numlines.txt
for /f "tokens=3 delims= " %%B in (numlines.txt) do set /A maxnum=%%B

for /F "tokens=* delims= " %%A in (dirA.txt) do (
find /V /C "%%A" dirB.txt >numlines.txt
for /f "tokens=3 delims= " %%B in (numlines.txt) do set /A foundnum=%%B
if %maxnum%==!foundnum! (echo %%A >>C:\AnotinB.txt
xcopy %%A c:\3)

)
echo ------------------------------------- >>C:\AnotinB.txt

My Change In Black .. Not Tested ..Let Me Know If It Needs More Working !
TheOutcaste's Avatar
Computer Specs
Senior Member with 1,537 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
29-Apr-2008, 09:16 PM #4
Quote:
Originally Posted by mdmini View Post
hi guys
i wanted to write a batch file that would compare 2 folders and give me the difference in another folder.
i got this script but i want the difference to go to a another folder. plsssssssssssss help....
this is the script i managed to get.......

@echo off


setlocal ENABLEDELAYEDEXPANSION
::Set dirA=%1
::Set dirB=%2

Set dirA=C:\1
Set dirB=C:\2

dir /B /O %dirA% >dirA.txt
dir /B /O %dirB% >dirB.txt


Echo Files that are found in BOTH folders %dirA% AND %dirB% >both.txt
Echo. >>both.txt
findstr /G:dirA.txt dirB.txt >>both.txt
echo ------------------------------------- >>both.txt

Echo Files that are found in folder %dirA% but NOT in folder %dirB% >AnotinB.txt
Echo. >>AnotinB.txt
find /V /C "this_is_an_absurd_string" dirB.txt >numlines.txt
for /f "tokens=3 delims= " %%B in (numlines.txt) do set /A maxnum=%%B

for /F "tokens=* delims= " %%A in (dirA.txt) do (
find /V /C "%%A" dirB.txt >numlines.txt
for /f "tokens=3 delims= " %%B in (numlines.txt) do set /A foundnum=%%B
if %maxnum%==!foundnum! (echo %%A >>AnotinB.txt
xcopy %%A c:\3) See Note 1

)
echo ------------------------------------- >>AnotinB.txt


Echo Files that are found in folder %dirB% but NOT in folder %dirA% >BnotinA.txt
Echo. >>BnotinA.txt
find /V /C "this_is_an_absurd_string" dirA.txt >numlines.txt
for /f "tokens=3 delims= " %%B in (numlines.txt) do set /A maxnum=%%B

for /F "tokens=* delims= " %%A in (dirB.txt) do (
find /V /C "%%A" dirA.txt >numlines.txt
for /f "tokens=3 delims= " %%B in (numlines.txt) do set /A foundnum=%%B
if %maxnum%==!foundnum! (echo %%A >>BnotinA.txt
copy c:\2 /f C:\3) See Note 2
)
echo. >>BnotinA.txt
echo ------------------------------------- >>BnotinA.txt

copy /B both.txt+AnotinB.txt+BnotinA.txt dupli.txt >nul
more dupli.txt

for %%A in (dirA.txt dirB.txt both.txt AnotinB.txt BnotinA.txt numlines.txt) do (
if exist %%A del %%A
)
A few suggestions:
I would suggest you add a Set dirC=c:\3 line so you can refer to your difference folder by a variable.
also, you need to clear this folder first, or set xcopy to force an overwrite, or it will pause for confirmation each time you run it.
To clear the folder use del /f/q %dirC%\*.*, or add the /Y switch to the xcopy command
For the dir commands, you don't really need the /O switch as it will make no difference how the names are sorted. But if you use it, it's best to specify the sort order. If the dircmd environment variable has been set, you could get unexpected results. So use /O:N for example.
You may also want to add the /A-D switch so directories will not be listed, just in case one or the other of the source folders has subfolders. It won't affect the files that end up in the difference folder, but the folder will be listed in the results file. If you need to check subfolder contents as well, that will require a bit more code.
If the extension is the same, you only need to specify it in the IF statement:
for %%A in (dirA dirB both AnotinB BnotinA numlines) do if exist %%A.txt del %%A.txt

Note 1
xcopy %%A c:\3)
You need to specify the path to %%A, else it uses the current folder, and it needs to be in quotes in case the file/folder name contains a space, so use:
xcopy "%dirA%\%%A" %dirC% >nul)

Note 2
copy c:\2 /f C:\3)
/f is not a valid switch. This line should match the previous one, just use the 2nd source folder:
xcopy "%dirB%\%%A" %dirC% >nul)

Finally, if you need the result file in the c:\3 folder, you need to specify the path. Replace dupli.txt with %dirC%\dupli.txt wherever it occurs.

The following will do the same without using temp files on the hard drive which have to be created and searched, which will speed it up a bit. This avoids creating a new numline.txt file for every filename that exists in dirA.

Code:
@echo off
Set _t0=C:\test1
Set _t1=C:\test2
Set _t2=C:\test3
:clear the results folder. Another option is to use the /Y switch on the Xcopy commands
del /f/q %_t2%\*.*
:set up info lines for each section of the report
Echo Files that are found in BOTH folders %_t0% AND %_t1% >_t0.txt
Echo. >>_t0.txt
Echo Files that are found in folder %_t0% but NOT in folder %_t1% >_t1.txt
Echo. >>_t1.txt
Echo Files that are found in folder %_t1% but NOT in folder %_t0% >_t2.txt
Echo. >>_t2.txt
For /F "delims=" %%I In ('dir /b/o:n /a-d "%_t0%"') Do If EXIST "%_t1%\%%I" (Echo %%I >>_t0.txt) ELSE (
xcopy "%_t0%\%%I" %_t2% >nul & echo %%I >>_t1.txt)
For /F "delims=" %%I In ('dir /b/o:n /a-d "%_t1%"') Do If NOT EXIST "%_t0%\%%I" xcopy "%_t1%\%%I" %_t2% >nul & Echo %%I >>_t2.txt
:write a separator line to each end each section
For /L %%I in (0,1,2) Do Echo ------------------------------------- >>_t%%I.txt
Copy /b _t0.txt+_t1.txt+_t2.txt %_t2%\dupli.txt >nul
:Cleanup
For /L %%C In (0,1,2) Do (del /f/q _t%%C.txt) & set _t%%C=
HTH

Jerry
__________________
Of course I know all the answers ; I just don't always match the answers to the right questions

Warning -- Windows spoken here. (Rated R for Strong Language and Violence -- When your Windows PC flies through a window, that's violent, right?)
vinod.bhanur's Avatar
Computer Specs
Junior Member with 9 posts.
 
Join Date: May 2008
Experience: Beginner
04-May-2008, 07:57 AM #5
execute batch file after every 15 minutes
hello friends. this is vinod.
my problem is , i want to execute batch file after every 15 min

how can i achieve this task plz suggest .
devil_himself's Avatar
Distinguished Member with 4,779 posts.
 
Join Date: Apr 2007
Location: India
Experience: Advanced
04-May-2008, 08:10 AM #6
Hello vinod ...Please Start Your Own Thread

)
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 04:11 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.