How to delete corrupted files using cmd?

Corrupted files are files that have become damaged or unstable, rendering them unusable. This can happen for a variety of reasons, such as a software malfunction, sudden power outage, or file system errors. Corrupted files can cause problems like crashing applications, displaying errors when trying to open the file, or missing data. It’s important to be able to identify and delete corrupted files, as they can accumulate and take up valuable storage space. Deleting corrupted files also helps prevent further issues down the line, as these unstable files can sometimes damage other files or system processes if left alone. This guide will walk through the steps for effectively locating and removing corrupted files using the Command Prompt in Windows.

Identify Corrupted Files

There are a few common symptoms that can indicate you have corrupted files on your Windows computer. Corrupted system files can lead to crashes, error messages, trouble opening files or programs, visual glitches or artifacts on screen, and general system instability [1]. Some signs to watch out for include:

  • Programs crashing frequently or freezing
  • Blue screen errors or error messages when starting up Windows
  • Problems opening certain files or running certain programs
  • Visual distortion, artifacts, or glitches on the screen
  • Windows failing to start correctly or booting into Safe Mode
  • Hard drive errors or bad sectors

Corrupted system files can affect any program or process that relies on those files. Some common locations where corruption occurs include the Windows Registry, system DLL files, boot files, and user profile settings. If you suspect corrupted files, you can scan your system to identify them.

Open the Command Prompt

To access the Command Prompt app and utilize its full functionality, you need to open it with administrative privileges. Here are a few methods to open Command Prompt as an administrator in Windows:

Press the Windows key + X and select “Command Prompt (Admin)” from the Power User menu.

Type “Command Prompt” in the Windows search bar, right-click on the top result, and select “Run as administrator.”

Press Windows key + R to open the Run dialog box. Type “cmd” and press Ctrl + Shift + Enter to launch Command Prompt as administrator.

From the Start menu, search for “Command Prompt,” right-click on it, and choose “Run as administrator.”

Running Command Prompt as administrator allows you to access powerful built-in commands and make changes that affect the whole system like deleting corrupted system files.

List All Files

The first step is to list all the files in the current directory to identify any potential corrupted files. The dir command shows an alphabetized list of all the files and folders in a directory. To list all files including in subfolders, use the dir command with the /s option:

dir /s

This recursively lists all the files in the current folder and subfolders. You can also use options like /b to show just file names rather than a table view. The dir command provides a quick overview of all files to inspect for any potential corruption or errors.

Identify Corrupted Files

The first step in deleting corrupted files using the command prompt is to identify which files are corrupted. We can use the command prompt’s ‘dir’ command to list all files in a directory, and then filter the output to only show corrupted files.

The attrib command in the command prompt is useful for finding corrupted files. Running “attrib -r -a -s -h *.*” will search all files in the current directory and subdirectories for the corrupted file attributes (EaseUS).

The attrib output will list any files marked as:

  • Read-only (R)
  • Archive (A)
  • System (S)
  • Hidden (H)

Any files showing those attributes may potentially be corrupted. We can then investigate those files further before deciding to delete.

Delete the Corrupted Files

To delete corrupted files in Windows using the Command Prompt, you can use the ‘del’ command. The basic syntax for deleting a file is:

del “filename”

For example, to delete a file called test.txt you would run:

del “test.txt”

This will immediately delete the file without any confirmation. To add a confirmation prompt before deleting, use the /p switch:

del /p “test.txt”

This will prompt you to confirm the deletion by entering Y or N.

To delete all files in a folder, you can use the * wildcard like this:

del *.*

This will prompt you to confirm deletion of all files in the current folder. Press Y to confirm or N to cancel.

So in summary, the ‘del’ command allows you to quickly delete corrupted files after identifying them, with optional confirmation prompts for safety.

Source: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/del

Delete System Files

To delete system files, such as files in Windows/System32, you will need administrative access in the command prompt. System files are protected and require elevated privileges to modify or delete.

Use the ‘del’ command but with the ‘/s’ switch to delete system files. For example:

del /s c:\Windows\System32\file.sys

This will force delete the system file. Be very careful when deleting system files as it can cause instability or crashes if you delete the wrong ones.

It’s recommended to create a system restore point before deleting system files so you can roll back if needed. Also be sure to have backups available. Deleting critical system files could result in being unable to boot into Windows.

Some key points when using ‘del’ on system files:

  • Open the command prompt as administrator
  • Use the ‘/s’ switch with ‘del’ to override system protection
  • Only delete files you are certain are safe to remove
  • Create a system restore point first as a precaution

Overall, exercise great caution when deleting system files in Windows using the command prompt. It’s easy to cause instability if you accidentally delete protected files.

Source: How to delete all system files using command prompt

Delete Read-Only Files

Read-only files cannot be deleted normally through the Windows interface or standard delete commands. To delete read-only files, you need to use the del command with the /f option which will force the deletion of read-only files.

Here are the steps to delete read-only files using the del /f command:

  1. Open Command Prompt as administrator.
  2. Navigate to the folder containing the read-only files you want to delete. For example:
    cd C:\Users\Name\Desktop\readonly_files
  3. Run the del /f command followed by the name of the read-only file. For example:

    del /f file1.txt
    This will force delete the read-only file1.txt.
  4. You can use wildcards if you want to delete multiple read-only files. For example:
    del /f *.txt
    This will delete all read-only .txt files.

The /f option forces the deletion and overrides the read-only attribute. Be careful when using del /f as you can accidentally delete important files. Also note that you need administrator privileges to delete read-only system files.

For more details see:
How to delete read-only files using Command Prompt

Restart Your Computer

It is important to restart your computer after deleting corrupted files to allow the operating system to fully clear out the deleted files and refresh itself [1]. When you delete a file in Windows, it is not immediately removed from your hard drive. Instead, Windows marks the space used by the file as available for new data. Restarting your computer completely clears out all files marked for deletion.

Restarting also refreshes your computer’s RAM and closes all open programs and processes. This allows Windows to start fresh, which can fix minor issues caused by those corrupted files. Any files Windows was having trouble accessing due to corruption will no longer be an issue after a restart. Essentially, restarting gives Windows a clean slate after removing those problematic corrupted files.

You should restart your computer immediately after deleting corrupted files using the Command Prompt. Allow time for the deletion process to fully complete before shutting down. Once restarted, your computer should run smoother without those corrupted files causing conflicts.

Conclusion

Deleting corrupted files through Command Prompt can be a straightforward process once you know the steps. First, you need to open the Command Prompt with admin privileges. Then use the ‘dir’ command to list all files, and look for ones marked as corrupted. Delete specific corrupted files by using the ‘del’ command along with the file path. For system or read-only files, you may need to take ownership or disable read-only status before deleting. Finally, restart your computer for the changes to fully take effect.

To avoid corrupted files in the future, make sure your hardware components like RAM and hard drives are functioning properly. Install the latest updates for your operating system, programs, drivers and security software. Don’t force shut down your computer if it’s frozen, allow it to fully complete processes first. Use antivirus software and don’t download suspicious files that could contain malware. Back up your data regularly in case you do need to remove corrupted files.

Leave a Comment