You can write protect a flash drive or an external hard drive to prevent accidental erasure.
Write Protect Disk
Open the command prompt as an administrator. Type cmd into the search field on the bottom left of your screen, then select “run as administrator” from the search results.
First type the following to start the disk partition utility.
diskpart
Type the following to list all the disks on your computer
list disk
Find the disk you want to write protect then type the following.
select disk ?
Replace the ? with the disk number. For example, in the screenshot above, the disk I want to write protect is disk 12. So I’d type select disk 12
To set the disk to read only type
attributes disk set readonly
Type exit when you’re done.
Clear Write Protect on USB Disk
Open the command prompt as an administrator, then type
diskpart
Type the following to list all the disks on your computer.
list disk
Find the disk you want then type the following. Replace the ? with the disk number
select disk ?
To remove the write protect attribute, type
attributes disk clear readonly
Type exit when you’re done.