Hi Welcome Batch Programmer.
In this lesson we learn about how to compare what inside a folder to what inside another folder, side by side.
PRE-REQUISITE
1. You need to know how to use setlocal enabledelayedexpansion
2. You need to know how to use FOR /F basically
3. You need to know how to use FOR /F with
4.
Code are:
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
REM This program will compare what inside a folder to what inside another folder, side by side.
REM We need to measure how many line in the 1st file
SET /a length_file_1 = 0
SET /a length_file_2 = 0
FOR /F "tokens=* delims=" %%i IN ('"dir /b %1"') DO SET /a length_file_1 = length_file_1 + 1 FOR /F "tokens=* delims=" %%i IN ('"dir /b %2"') DO SET /a length_file_2 = length_file_2 + 1 echo File length at %1 is: %length_file_1% files or folders. echo File length at %2 is: %length_file_2% files or folders. REM Next, we need to compare which one is bigger SET /a iterator_length = 0 IF %length_file_1% GEQ %length_file_2% SET /a iterator_length = %length_file_1% IF %length_file_2% GEQ %length_file_1% SET /a iterator_length = %length_file_2% REM Next echo the iterator length to the screen echo Iterator length: %iterator_length% REM extract all the data into two arrays REM ==================================== SET /a indeks = 0 FOR /F "tokens=* delims= eol=;" %%i IN ('dir /b "%1"') DO SET /a indeks = indeks + 1& SET a[!indeks!]=%%i SET /a indeks = 0 FOR /F "tokens=* delims= eol=;" %%i IN ('dir /b "%2"') DO set /a indeks = indeks + 1& SET b[!indeks!]=%%i REM Print out using for /L REM ====================== IF %length_file_1% GEQ %length_file_2% echo No, This colomn is for %1 %TAB%,%TAB% This colomn is for %2&FOR /L %%i IN (1,1,%length_file_1%) DO echo %%i, !a[%%i]! %TAB %,%TAB% !b[%%i]! IF %length_file_2% GEQ %length_file_1% echo No, This is colomn is for %2 %TAB%,%TAB% This colomn is for %1&FOR /L %%i IN (1,1,%length_file_2%) DO echo %%i, !a[%%i]! %TAB %,%TAB% !b[%%i]!
In this lesson we learn about how to compare what inside a folder to what inside another folder, side by side.
PRE-REQUISITE
1. You need to know how to use setlocal enabledelayedexpansion
2. You need to know how to use FOR /F basically
3. You need to know how to use FOR /F with
4.
Code are:
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
REM This program will compare what inside a folder to what inside another folder, side by side.
REM We need to measure how many line in the 1st file
SET /a length_file_1 = 0
SET /a length_file_2 = 0
FOR /F "tokens=* delims=" %%i IN ('"dir /b %1"') DO SET /a length_file_1 = length_file_1 + 1 FOR /F "tokens=* delims=" %%i IN ('"dir /b %2"') DO SET /a length_file_2 = length_file_2 + 1 echo File length at %1 is: %length_file_1% files or folders. echo File length at %2 is: %length_file_2% files or folders. REM Next, we need to compare which one is bigger SET /a iterator_length = 0 IF %length_file_1% GEQ %length_file_2% SET /a iterator_length = %length_file_1% IF %length_file_2% GEQ %length_file_1% SET /a iterator_length = %length_file_2% REM Next echo the iterator length to the screen echo Iterator length: %iterator_length% REM extract all the data into two arrays REM ==================================== SET /a indeks = 0 FOR /F "tokens=* delims= eol=;" %%i IN ('dir /b "%1"') DO SET /a indeks = indeks + 1& SET a[!indeks!]=%%i SET /a indeks = 0 FOR /F "tokens=* delims= eol=;" %%i IN ('dir /b "%2"') DO set /a indeks = indeks + 1& SET b[!indeks!]=%%i REM Print out using for /L REM ====================== IF %length_file_1% GEQ %length_file_2% echo No, This colomn is for %1 %TAB%,%TAB% This colomn is for %2&FOR /L %%i IN (1,1,%length_file_1%) DO echo %%i, !a[%%i]! %TAB %,%TAB% !b[%%i]! IF %length_file_2% GEQ %length_file_1% echo No, This is colomn is for %2 %TAB%,%TAB% This colomn is for %1&FOR /L %%i IN (1,1,%length_file_2%) DO echo %%i, !a[%%i]! %TAB %,%TAB% !b[%%i]!
Tidak ada komentar:
Posting Komentar