Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

Question

how to remove files with spaces

Mar 23, 2012 7:34AM PDT

Hi, y'all.

I need to remove a few files from the Fonts folder in my Windos XP via a batch file.I've been able to remove files without spaces in the filename but the method i use doesn't seem to delete files that have spaces in the filename.

This is how i have the batch file set up:

@echo off

del /f /q C:\WINDOWS\Fonts\Helvetica LT 93 Black Extended.ttf
del /f /q C:\WINDOWS\Fonts\JaneAust.ttf
pause

The error shows 'file not found' for the file with spaces.

How do i remove the file with spaces then? Should i rename the file to remove the empty spaces in the filename or is there a cleaner way?

Thanks

Discussion is locked

- Collapse -
Answer
Ouch!
Mar 23, 2012 7:39AM PDT

Why would you want to do that?

In my Win 7 system I have hundreds of fonts, and a large majority of them have spaces in their file names.

Care to tell us more before you damage the system irreparably?

Mark

- Collapse -
damaging the system with a font remove. talk about apoclypse
Mar 23, 2012 7:48AM PDT

i regulalry install fonts to work with customer files which include needed fonts.
i want to create a batch each time i install these fonts so i can remove then upon completion.
i obvioulsy don't want hundreds of fonts installed on my system.
so removing them with a simple batch run will be ideal.

- Collapse -
Good and now we know
Mar 23, 2012 8:39AM PDT

that you are a professional, that's fine.

For filenames with spaces, enclose the file name with quotes, eg "Helvetica LT 93 Black Extended.ttf"

What are you doing about the registry entries?

Mark

- Collapse -
im no pro, but no need to scare the crap out of people.
Mar 23, 2012 8:59AM PDT

well i didnt know about having to remove the registry entries.

but i guess a quick google search will help me out.

thanks for the enclosed filenames method.

cheers!

- Collapse -
You will likely discover that ...
Mar 23, 2012 9:42AM PDT

you need to enclose the full path AND file name in quotes for the batch file to work.

As for the registry entries for each font, they are located at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts

To remove them you could make use of a .REG file as follows.

This is how the font would be added by using a reg file (let's call it FontAdd.reg):

REGEDIT4

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts]
"OCR-B 10 Pitch BT (TrueType)"="OCRB10N.TTF"
"Alternate Gothic No.2 BT (TrueType)"="tt0542m_ttf"

This is how it would be removed using a reg file we could name FontRemove.reg (note that everything is the same EXCEPT the actual file name is replaced with a minus sign):


REGEDIT4

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts]
"OCR-B 10 Pitch BT (TrueType)"=-
"Alternate Gothic No.2 BT (TrueType)"=-

If you have never made a reg file you simply use notepad to create it using the bolded text. The top line is the version of registry which is backward compatible but not vice versa. Instead of REGEDIT4 you could also use Windows Registry Editor Version 5.00

The next line is the specific key you are working with and the lines beneath that are the individual values shown in the right window of regedit. After all the keys are listed that you want to remove you press the enter key in notepad to start a new line then save the file with whatever name you want with the .reg file extension.

Depending on the number of fonts you use for your projects you might consider just copying the font into some directory (maybe named for the project) and activating them for your current session as follows:

1. Fonts my be temporarily installed in windows without placing them in
the Fonts folder.
2. To do this, double click on the .ttf file and it will
open in a preview.
3. Minimize this preview and as long as you leave it
open, the font will be available in your windows programs for use.
4. You
may have to close and reopen some programs to get them to load the font so it is best to open the fonts BEFORE opening the program(s) you will need the fonts in.

This eliminates the need for batch files for deleting the fonts and reg files for removing installed fonts from the registry.
.

- Collapse -
thanks
Mar 23, 2012 12:22PM PDT

thank you for the extensive post.

thats a fun fact, that as long as the font is open in preview it works as if it was installed.

thanks again edward

- Collapse -
no need to clear registry
Mar 23, 2012 8:22PM PDT

it seems that there is no need to clear the registry though, as this get's updated when the font is removed (with running the bat file).

regards

- Collapse -
or is it?
Mar 23, 2012 11:23PM PDT

should i run the reg any way?