Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8377639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:43:25+00:00 2026-06-09T15:43:25+00:00

I use Windows 7, and I a want to build a batch-file with to

  • 0

I use Windows 7, and I a want to build a batch-file with to complete the following task:

Delete all files with 4 characters in name in the C:\images directory.
E.g. 1234.jpg 7123.jpg, 8923.jpg, 7812.jpg, 1245.jpg, 0067.jpg, 0001.jpg, 0010.jpg, 0060.jpg etc.

Is that possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:43:27+00:00Added an answer on June 9, 2026 at 3:43 pm

    This solution will erase all files whose name part before the dot have 4 characters, and possibly those that have a shorter part before the dot.

    ERASE C:\images\????.*
    
    • ? stands for any character (or sometimes no character at all, see below)
    • * stands for any sequence of characters.

    What different Windows versions ?

    Under Windows 98 (and I have a gut feeling that this is also valid for “pure” DOS versions without full support for long FAT names, which would include win95 and older, and maybe Windows Millennium), the ? stands for exactly one character.

    Based on @dbenham’s comment, I get that in later versions of Windows, ? stands for 0 or 1 characters.

    What about FAT short names ?

    Now for the tricky parts : What about names with a leading dot (i.e. 0 characters before the first dot) ? What about files with multiple dots ?

    Trailing dots are stripped before anything is performed, so the extension of abc.def..... is def, and its base is abc.

    The dot is at a fixed position in the short name, and is present even for files without an extension. That’s why *.* matches all files, even those without an extension.

    Leading dots, multiple dots, extensions of more than 3 characters and base (before the dot) parts of more than 8 characters are invalid in short FAT names (also called DOS names), so a file whose long name (displayed under Windows) is one of those will have a made-up short name, looking like POBASE~N.POE, where :

    • POBASE is a part of the base (usually the beginning, stripped of unusual characters),
    • ~ is a literal tilde character,
    • N is a single or multiple-digit number, and is usually the smallest number that doesn’t clash with existing names,
    • POE is a part of the extension (usually the beginning, stripped of unusual characters), where the extension is the part after the last dot,
    • and all the parts are capital letters or digits.

    I created the following files, in that order :

    • .ab had the short name AB~1
    • a.b.c had the short name AB~1.C
    • a.bcde had the short name A~1.BCD
    • a.x y (notice the space) had the short name a.xy
    • ..ab had the short name AB~2, since AB~1 was already there (first example)
    • a.b, a.b., a.b.., a.b... are all equivalent names for the same file (i.e. to create a.b... will overwrite a.b if it exists).

    When you run the command dir ????.* on an old Windows 98 system, the following files will be matched :

    • AB~1, with long name .ab
    • AB~1.C, with long name a.b.c
    • AB~2, with long name ..ab

    Now, while Vista and 7 have tried to throw most DOS legacy out of the window (pun intended), there are still some remnants : if you type C:\PROGRA~1 in the address bar of an explorer window, you’ll land into (the half-baked localized variant of) C:\Program files, and if you plug in a FAT-formatted USB key, the files will have short names. I’m not sure if the wildcards will match against these short names, but here are some “fun” facts, that show it’s not even worth investigating :

    Fun facts

    • In a french version of Windows 7, C:\Program files will show up in explorer as C:\Programmes, but if you try to cd C:\Programmes, it will fail, so the translated names don’t seem to be used by the command-line.
    • On the same Windows 7, ????????.? (8.1 question marks) will match with a.b.c (which is only 5 characters), but anything shorter (like ???????.? with 7.1 question marks) won’t match it.
    • On the same Windows 7, ????????.? will match foo, although there is no dot in foo.

    Conclusion

    To conclude, if you want to write a program that reliably deletes files with exactly four characters before the first (or last) dot, use some of the other solutions, don’t use wildcards.

    However, be warned that older windows versions don’t have all those fancy-dancy scripting capabilities for getting the length of a string with awkward syntax (I mean, seriously, if "!n:~3,1!" neq "" echo del "%%F", it’s nearly as bad as zsh globbing modifiers.

    All this would be so much simpler if windows didn’t have three layers of file naming (FAT short names, “actual” file name, and translated file name), and if they hadn’t chosen to change the meaning of ?.

    Sigh

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to build desktop application for Windows OS and use Google Drive to
I want to build a static library (*.LIB file) GNU libiconv on windows to
I want to build a windows service that will use a remote encoding service
I want to use WPF windows in a legacy win32 application. I'd like to
When I want to use multiple windows in my code, I normally do it
First, please forgive my bad english ;) I want to use the windows function
I'm new to emacs and I want to use ensime in Windows. I had
I want to use gestures on a windows mobile phone. For example (using .net
I want to use the June 2010 SDK rather than the Windows 8 SDK
I want to use an AES 256-bit web service with a Windows Mobile 6.1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.