Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Trying to write a batch file to check for an existing file.

44 views
Skip to first unread message

FontLeroy

unread,
Jan 14, 2012, 7:55:22 PM1/14/12
to
This should be "old hat" but I haven't written a batch file in AGES,
sadly. I had actually posted a similar question here years ago, but
life took over and I can't find the post.

Basically, I had a lot of fonts. What I'd like to do is when sorting
my fonts with a batch file, I would prefer if a font that is about to
be copied is checked to see if it already exists (dont' care about
file size at this point, unless there is a way to determine that from
a batch file.)

if the file DOES exist in the destination folder, I would like that
file to be moved to a folder we'll call for now DUPES.

If the file does NOT already exist in the destination folder, it
should be moved there.

I WISH more than anything there was a switch in the move command to do
that testing for me (us / the world)...

With that, i will display a sample listing a directory structure and I
hope SOMEONE out there can figure this out because it has been driving
me crazy!

Sample Directory:

aa.ttf
ab.ttf
ac.ttf

Sample folder structure:

e:\fonts\A\aa
e:\fonts\A\ab
e:\fonts\A\ac
etc...

After my fonts are prepped (renamed, dupes killed, etc) I just use a
simple batch file to sort by the first 2 characters of the fonts file
name.

Why oh why can't I just do a simple check first?

I am running Windows XP SP3 if that matters.

Thanks to ANYONE who can kick me in the head and help me figure this
out!

FontLeroy

Franc Zabkar

unread,
Jan 14, 2012, 10:17:55 PM1/14/12
to
On Sat, 14 Jan 2012 19:55:22 -0500, FontLeroy <font-...@hotmail.com>
put finger to keyboard and composed:

>if the file DOES exist in the destination folder, I would like that
>file to be moved to a folder we'll call for now DUPES.
>
>If the file does NOT already exist in the destination folder, it
>should be moved there.

You could use the "IF EXIST" or "IF NOT EXIST" batch commands.

IF [NOT] EXIST filename command

Type "IF /?" at the DOS prompt for the syntax.

Example:

if not exist product.dat echo Can't find data file

- Franc Zabkar
--
Please remove one 'i' from my address when replying by email.

foxidrive

unread,
Jan 15, 2012, 12:15:39 AM1/15/12
to
On 15/01/2012 11:55, FontLeroy wrote:
> This should be "old hat" but I haven't written a batch file in AGES,
> sadly. I had actually posted a similar question here years ago, but
> life took over and I can't find the post.

Here it is. See if the code that was supplied is any good and take it from there.

http://groups.google.com/group/alt.msdos.batch/browse_thread/thread/86900f1a68778c80


--
Regards,
Mic

FontLeroy

unread,
Jan 15, 2012, 2:17:12 PM1/15/12
to
Thank you both foxidrive for finding my original post and Franc for
the great tip!
0 new messages