Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I have a txt file (eg. files.txt) with the following info: filename filesize. ie:
01a2316a90e2ef0490a7dbb5fd4a033c.exe 6689
010c1cc11110a1c6e4ece159c8f44c2e.rar 1028I need a batch or vbscript to loop through this files.txt and only if a file exists with that name AND exact file size, then to delete that file.
If anyone can help me with this, that would be great.
TIA, Anthony

@echo off & setLocal EnableDelayedExpansion
for /f "tokens=1-2 delims= " %%a in (files.txt) do (
if %%~Za equ %%b del %%a
)
=====================================
If at first you don't succeed, you're about average.M2

Hi,
Thanks for the quick turnaround and this works GREAT! As I needed to copy some files as well based on the same criteria (name/size) I have modified your example to copy the files instead of deleting by changing:
if %%~Za equ %%b del %%ato
if %%~Za equ %%b copy %%a k:\testbut I get an "syntax of the command is incorrect" error for the files it does find when I execute this - I removed the echo off, and I see this:
(if EQU copy 01a2316a90e2ef0490a7dbb5fd4a033c.exe 6689 k:\test ) The syntax of the command is incorrect.What am I doing wrong?

Post your whole script.
=====================================
If at first you don't succeed, you're about average.M2

@echo off & setLocal EnableDelayedExpansion for /f "tokens=1-2 delims= " %%a in (files.txt) do ( if %%~Za equ %%b copy %%a c:\tempdir )

I dunno; works here.
=====================================
If at first you don't succeed, you're about average.M2

Hmm, weird ... keeps giving me the 'syntax of the command is incorrect' error ?? Could it be because the copy action is being run under Vista? The initial batch (delete) was under XP, though it runs also under Vista - I have just checked. I'm stumped!

I'd be very surprised if Viista COPY was much different.
The really troubling bit is the line when you disabled ECHO OFF and got this:
(if EQU copy 01a2316a90e2ef0490a7dbb5fd4a033c.exe 6689 k:\test )
Is that EXACTLY the msg?
=====================================
If at first you don't succeed, you're about average.M2

Yes it is ... I have zipped my batch file, files.txt and the output I get (output.log). You can get it from:

Hi Mechanix2Go,
It should do - I have just checked it is OK (its a ZIP file).
Otherwise I could mail it. I'll use the mail form.

I got the zip; checking it now...
Give me a few minutes.
=====================================
If at first you don't succeed, you're about average.M2

Whatever whitespace character separates the filename and size (a tab, apparently) isn't what you specify in your delims (a space). Replace your delims= " to
delims= "(there's a tab there)

It turns out that in your files.txt the name and size are separated by a tab. When I changed the tab to a space the problem went away. I have no idea why.
Here's a script to change tab to space.
===============================
:: NOTAB.BAT
:: chg tab to space@echo off > newfile & setLocal EnableDelayedExpansion
for /f "tokens=1-2 delims= " %%a in (files.txt) do (
echo %%a %%b >> newfile
)
=====================================
If at first you don't succeed, you're about average.M2

oops
The solution is to fix the batch.
==================================
@echo off & setLocal EnableDelayedExpansionfor /f "tokens=1-2" %%a in (files.txt) do (
if %%~Za equ %%b copy %%a c:\tempdir
)
=====================================
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |