Facebook Twitter Instagram
    • Privacy Policy
    • Facebook Page
    • Channel
    • Twitter
    • Sitemap
    Facebook Twitter Instagram
    TechulkTechulk
    • Menu
      • Blogging
      • Android
      • Apps
      • Rooting/Flashing
      • Games
    • How-To
    • Troubleshooting
    • Reviews
    • News
      • Latest
      • Trending
      • Around The Web
    • Affiliate Disclosure
    TechulkTechulk
    Home»How-To»How to Delete File and Folder in Command Line
    How-To

    How to Delete File and Folder in Command Line

    Shravan DasBy Shravan DasJuly 15, 2020No Comments4 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr WhatsApp Email
    Share
    Facebook Twitter LinkedIn WhatsApp Pinterest Email

    Sometimes deleting files or folders do not work on Windows, from the File Explorer. You may experience access denied or locked file message.

    Very often, these are video or MP3 files that are recalcitrant to delete or sometimes if the file name is too long.

    In this case, you can try to delete the files from the command line.

    By deleting a file from the Windows command prompt using CMD commands. We can also go further.

    Indeed, this deletion is also accessible by the command prompt from the advanced Windows recovery options when Windows does not start.
    Although it is however possible to find a graphical environment from a Live CD.

    This tutorial explains how to delete a file or folder from the command line.

    Contents

    • CMD Commands to Delete Files
      • Del Command
      • RMDIR Command
    • Resetting Permission Using Command Line

    CMD Commands to Delete Files

    In order to obtain the highest access, it is recommended to launch the command prompt in the admin.

    Just do a search on the command prompt then right click and run as an administrator.

    Run command line as admin
    Run command line as admin

    The commands we will use in this article are:

    • del: delete a file
    • rd or rmdir: delete a folder
    • takeown: allows to become the owner of files
    • icalcs: allows you to redefine file permissions, you must be the owner of the files for this.

    The principle is to use the del or rmdir command followed by the file or folder you wish to delete.

    You must give the full path of the file you wish to delete.

    The user profile is located in C: \ Users \ <yourusername> (replace with your uusername)

    • The desktop path is:  C: \ Users \ <username> \ Desktop
    • The path to the download folder is: C: \ Users \ <username> \ Downloads

    You can use the% USERPROFILE% variable to also get the full path that will work on any version of Windows since% USERPROFILE% points to C: \ Users \ <username>, so the desktop path becomes% USERPROFILE% \ Desktop

    Del Command

    This is the delete command, it only works to delete files and does not work to delete folders.

    The syntax for the del command is as follows:

    del \path\filename

    Example:

    Deleting File using del command
    Deleting File using del command
    del C:\Users\monuser\Desktop\sampledoc.txt

    If no full path is given, del then attempts to delete the file in the current directory.

    So if you have this:

    del sampledoc.txt

    So you are in the Windows folder, del will try to delete the file from the Windows folder, so C: \ Windows \ sampledoc.txt

    Finally, it is possible to delete the entire contents of a folder using the / S parameter:

    del /S C:\Users\username\Desktop\foldername

    RMDIR Command

    The rmdir command allows you to delete a folder, it works in the same way as the del command.

    So to delete the demo folder from the user’s desktop:

    deleting folder using rmdir command
    deleting folder using rmdir command
    rmdir C:\Users\username\Desktop\foldername

    If you want to delete all the sub-folders, you will have to use the / S parameter

    rmdir /S C:\Users\username\Desktop\foldername

    Resetting Permission Using Command Line

    If you do not have permissions and security on the folder, you may encounter an error message during deletion.

    It is quite possible to reset file permissions on the command line.

    The takeown command allows you to define yourself as the owner of the files.

    takeown /F "C:\Program Files (x86)\UCBrowser" /A /R
    icacls "C:\Program Files (x86)\UCBrowser" /grant:r Users:F /T
    icacls "C:\Program Files (x86)\UCBrowser" /grant:r administrators:F /T
    rmdir /S "C:\Program Files (x86)\UCBrowser"

    Then we use the icalcs command to modify the permissions, the two commands give the full control over the user and administrator groups (it’s the: F for full which redefines these permissions).

    Once the permissions have been modified, we use the rmdir command to delete the folder as explained in the previous paragraph.

    You might also like-

    • Download and Install Windows Update using Powershell
    • Transfer data to new Windows 10 PC
    Share. Facebook Twitter Pinterest LinkedIn Tumblr WhatsApp Email
    Shravan Das
    • Website
    • Facebook
    • Twitter
    • Instagram
    • LinkedIn

    A Tech Geek who loves to write about WordPress blogging, How-To's, and fixing errors. He founded techulk with the sole purpose of providing visitors the exact information they need with simple and step-by-step working explanations.

    Related Posts

    Canva Pro: Your Ultimate Online Design Tool (2024)

    December 10, 2024

    A Beginner’s Guide to Understanding Roku and How It Works

    April 24, 2023

    Does Panda Express take Apple pay

    March 10, 2023

    Does Safeway take Apple Pay?

    March 1, 2023

    Does Wingstop Take Apple Pay

    February 21, 2023

    Does Home Depot Take Apple Pay?

    February 17, 2023
    Add A Comment

    Leave A Reply Cancel Reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    – Ads –
    Recent Comments
    • Shravan Das on What is CAMRIP, DVDRIP, HDTS, HDTV & other releases?
    • Gumby on What is CAMRIP, DVDRIP, HDTS, HDTV & other releases?
    • ajay kumar on Kerala vision broadband Review & Plans
    • Ravindran on Change Jio fiber login password | Easy Guide 2020
    – Ads –
    Facebook Twitter YouTube Instagram
    • Privacy Policy
    • Facebook Page
    • Channel
    • Twitter
    • Sitemap
    © 2025 Techulk

    Type above and press Enter to search. Press Esc to cancel.