Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
garf
- Posts: 3
- Joined: 21 Jan 2013 08:37
#1
Post
by garf » 25 Jan 2013 04:11
Hi,
I have a filelist FL with a few filenames:
I've populated 2 arrays lf (localfile) en rf (remote file) with a lot of data. For example 2 lines like this but there are a lot more:
Code: Select all
set lf[test1][size]
set rf[test1][size]
I want to compare the 2 arrays in a new for-loop but I have a problem with that:
Code: Select all
for %%z in (%FL%) do (
if %rf[%%z][size]%==%lf[%%z][size]% (
echo equal
) else (
echo not equal
)
)
I guess it's a problem with the merging of the % ... how can I resolve this?
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#2
Post
by foxidrive » 25 Jan 2013 04:54
Seeing the real information helps enormously.
Too often we'd develop a solution for a problem but then it changes dramatically because of information we were unaware about.
Alternatively you can describe what you are doing with the local and remote directories and we may see an easier solution.
-
garf
- Posts: 3
- Joined: 21 Jan 2013 08:37
#3
Post
by garf » 25 Jan 2013 05:12
I want to check if the filedate, time en size are the same for some files on my pendrive so they are up to date after running the bat file attached here.
If it isn't equal to the server it'll copy the file from to server to my pendrive.
rd = remote directory, it's my server
rf = remote file on the server
lf = local file on my pendrive
Code: Select all
@echo off
set FL=test1.pkg test2.pkg test3.pkg test4.pkg test5.pkg test6.pkg test7.pkg test8.pkg test9.pkg test10.pkg test11.pkg test12.pkg test13.pkg test14.pkg test15.pkg test16.pkg test17.pkg test18.pkg test19.pkg
set rd=\\10.133.145.1\admin\dis\in_tray\
set flag=
for /f "skip=3 tokens=1-3,*" %%a IN ('dir %CD%%FL% /a-d /tc') do (
if /i "%%d"=="bytes" set flag=1
if not defined flag if not "%%d"=="" (
set lf[%%d][cdate]=%%a
set lf[%%d][ctime]=%%b
set lf[%%d][size]=%%c
)
)
for /f "skip=3 tokens=1-3,*" %%a IN ('dir %rd%%FL% /a-d /tc') do (
if /i "%%d"=="bytes" set flag=1
if not defined flag if not "%%d"=="" (
set rf[%%d][cdate]=%%a
set rf[%%d][ctime]=%%b
set rf[%%d][size]=%%c
)
)
for %%z IN (%FL%) do (
if %lf[%%z][cdate]%==%rf[%%z][cdate]% (
echo dont copy
) else (
echo copy
rem cp ... still to do
)
)
The 2 first for-loops run perfectly but the last for-loop has a problem with the compare of lf and rf.
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#4
Post
by foxidrive » 25 Jan 2013 05:38
This is untested but should work, with luck.

Code: Select all
@echo off
for %%a in (
test1.pkg
test2.pkg
test3.pkg
test4.pkg
test5.pkg
test6.pkg
test7.pkg
test8.pkg
test9.pkg
test10.pkg
test11.pkg
test12.pkg
test13.pkg
test14.pkg
test15.pkg
test16.pkg
test17.pkg
test18.pkg
test19.pkg
) do (
set copyfile=1
for %%b in ( \\10.133.145.1\admin\dis\in_tray\%%a ) do (
if "%%~ta"=="%%~tb" if "%%~za"=="%%~zb" (set copyfile=)
if defined copyfile copy /b \\10.133.145.1\admin\dis\in_tray\%%a .
)
)
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#5
Post
by foxidrive » 25 Jan 2013 05:46
This version should handle creation time, if you want that but it will look in subdirectories of the in-tray too, if that is an issue.
Code: Select all
@echo off
for %%a in (
test1.pkg
test2.pkg
test3.pkg
test4.pkg
test5.pkg
test6.pkg
test7.pkg
test8.pkg
test9.pkg
test10.pkg
test11.pkg
test12.pkg
test13.pkg
test14.pkg
test15.pkg
test16.pkg
test17.pkg
test18.pkg
test19.pkg
) do (
set copyfile=1
for /f "delims=" %%x in ( ' dir /b /tc "%%a" ' ) do (
for /f "delims=" %%y in ( ' dir /b /tc /s "\\10.133.145.1\admin\dis\in_tray\%%a" ' ) do (
if "%%~tx"=="%%~ty" if "%%~zx"=="%%~zy" (set copyfile=)
if defined copyfile copy /b \\10.133.145.1\admin\dis\in_tray\%%a .
)
)
)