Hi, sorry to interrupt once again, recently I came up with a batch program that compares files in local disk and usb drive. It looks like this:
@echo off
cls
setLocal EnableDelayedExpansion
echo.
echo ------------------------------------
echo Updating files..
echo ------------------------------------
echo.
for %%a in (D E F G H I J L M N O P Q R S T U V W X Y Z) do (
if exist "%%a:" set "thumbdrive=%%a:"
)
set harddisk=c:\
set /p thumbdrive="Please specify your source (pendrive) folder: "
set /p harddisk="Please specify your destination (harddisk) folder: "
for /f %%i in ('dir /b/a-d "%harddisk%\*" "%thumbdrive%\*"^|sort') do (
set "$i=%%$i:%%i=%%"
if defined $i (
if not exist "%harddisk%\%%i" (echo :The following file is not exist: %%i & copy "%thumbdrive%\%%i" "%harddisk%\%%i") else (
fc "%harddisk%\%%i" "%thumbdrive%\%%i" >nul&& echo :existing files: %%i|| echo :^< ^>: %%i)))
set "$i=%%i"
)
pause
-----------------------------------------------------------------------------------------------------------------------------------------
it works but the only problem is I do not want to specify the drive letter from c drive. For example, i want to compare e:\test and c:\test. I run the program, menu came up "Please specify your source (pendrive) folder:\test" Please specify your destination (harddisk) folder:\test", unfortunately it cannot read the destination folder unless you put like this: "Please specify your destination (harddisk) folder:c:\test", need help??tq
Problems with comparing files
Moderator: DosItHelp
Re: Problems with comparing files
Hi,
I have made the changes to your code,
the code was as follows
cmp.bat:
@echo off
cls
setLocal EnableDelayedExpansion
echo.
echo ------------------------------------
echo Updating files..
echo ------------------------------------
echo.
for %%a in (D E F G H I J L M N O P Q R S T U V W X Y Z) do (
if exist "%%a:" set "thumbdrive=%%a:"
)
set harddisk=c:\
set /p thumbdrive="Please specify your source (pendrive) folder: "
set /p harddisk="Please specify your destination (harddisk) folder: "
set thumbdrive=%thumbdrive%:\test
set harddisk=%harddisk%:\test
for /f %%i in ('dir /b/a-d "%harddisk%\*" "%thumbdrive%\*"^|sort') do (
set "$i=%%$i:%%i=%%"
if defined $i (
if not exist "%harddisk%\%%i" (echo :The following file is not exist: %%i & copy "%thumbdrive%\%%i" "%harddisk%\%%i") else (
fc "%harddisk%\%%i" "%thumbdrive%\%%i" >nul&& echo :existing files: %%i|| echo :^< ^>: %%i)))
set "$i=%%i"
)
pause
the output is as follows:
------------------------------------
Updating files..
------------------------------------
Please specify your source (pendrive) folder: c
Please specify your destination (harddisk) folder: d
:existing files: a.bat
:existing files: a.bat
:existing files: url.bat
:existing files: url.bat
Press any key to continue . . .
just give the directory name as c,d,....,
dont even specify ":"
thank you
shiva shankar
I have made the changes to your code,
the code was as follows
cmp.bat:
@echo off
cls
setLocal EnableDelayedExpansion
echo.
echo ------------------------------------
echo Updating files..
echo ------------------------------------
echo.
for %%a in (D E F G H I J L M N O P Q R S T U V W X Y Z) do (
if exist "%%a:" set "thumbdrive=%%a:"
)
set harddisk=c:\
set /p thumbdrive="Please specify your source (pendrive) folder: "
set /p harddisk="Please specify your destination (harddisk) folder: "
set thumbdrive=%thumbdrive%:\test
set harddisk=%harddisk%:\test
for /f %%i in ('dir /b/a-d "%harddisk%\*" "%thumbdrive%\*"^|sort') do (
set "$i=%%$i:%%i=%%"
if defined $i (
if not exist "%harddisk%\%%i" (echo :The following file is not exist: %%i & copy "%thumbdrive%\%%i" "%harddisk%\%%i") else (
fc "%harddisk%\%%i" "%thumbdrive%\%%i" >nul&& echo :existing files: %%i|| echo :^< ^>: %%i)))
set "$i=%%i"
)
pause
the output is as follows:
------------------------------------
Updating files..
------------------------------------
Please specify your source (pendrive) folder: c
Please specify your destination (harddisk) folder: d
:existing files: a.bat
:existing files: a.bat
:existing files: url.bat
:existing files: url.bat
Press any key to continue . . .
just give the directory name as c,d,....,
dont even specify ":"
thank you
shiva shankar