Cannot erase USB flash drive, "name invalid"

The problem:

  1. Created a bootable USB flash drive for Windows 10 for my HTPC, but after adding the files I just couldn’t get it to work (ended up burning to a CD and using an external CD drive instead).
  2. Later, tried adding new personal files to said USB but couldn’t. So I tried to erase.
  3. Got an error when attempting to erase. Here’s what happened…
    1. Goto Disk Utility -> Erase
    2. Received Error: “Invalid name. Operation failed…”

This is how to fix it:

  1. Open Terminal
  2. Type in diskutil list to determine what the disk number is
  3. Then type in diskutil eraseVolume [HFS+] [NAME] [DISK#]
    1. Where [HFS+] is the erase type you want (I just left it as HFS+)
    2. And [NAME] is the new name you want the disk to be called
    3. And [DISK#] is the disk number returned in Step 2
  4. In my case, I did (see below): diskutil eraseVolume HFS+ prince disk1
  5. Problem solved!

erase usb flash drive macos name invalid