Remove stubborn folder, on external drive, using cmd window


  1. Posts : 1,002
    XP Pro (x86) | 7 HP (x86) & (x64) | 7 Pro (x64)
       #1

    Remove stubborn folder, on external drive, using cmd window


    I had a stubborn empty folder on an external HD that would not delete.
    Windows alert "cannot delete <folder name> because there is a file open in the folder " (words to that effect)
    Stubborn folder was empty (I checked for very hidden files and folders)

    Unlocker (3rd party program) would not delete it. (As administrator)

    Sometimes changing the folder name will resolve a stubborn folder's deletion, but I found a YouTube tutorial Remove stubborn files or folders from your Windows system which demonstrated using the CMD window. I just had to try it !

    As administrator (cmd window) I could not change to the final parent folder of the sticky-folder to create the list of 8.39 files.
    The parent folder has a space and brackets "()" in it.

    I was trying to remove the Tools folder in an external HD F:\FolderA\FolderB\Folder (gnc)\Tools
    When I tried to change-directory from ...
    C:\Windows\system32 ... to ... F:\FolderA\FolderB\Folder (gnc)
    ... result remained as "C:\Windows\system32"
    With the space in the "Folder (gnc)" ... I tried wrapping the F-drive path in quotes (x1, x2 x3)

    But always resulted in the default "C:\Windows\system32>"
    Code:
    C:\Windows\system32>cd F:\FolderA\FolderB\Folder (gnc) 
    C:\Windows\system32>cd "F:\FolderA\FolderB\Folder (gnc)"
    C:\Windows\system32>cd ""F:\FolderA\FolderB\Folder (gnc)""
    C:\Windows\system32>cd """F:\FolderA\FolderB\Folder (gnc)"""
    Changing the sticky-folder's name resolved the deletion but I would like to understand why the cmd expression would not work

    Where did I go wrong ?

    Thank you :)
      My Computer


  2. Posts : 521
    Windows 7 Ultimate x64 Service Pack 1
       #2

    Here is the syntax of the CD command:

    Code:
    Displays the name of or changes the current directory.
    
    CHDIR [/D] [drive:][path]
    CHDIR [..]
    CD [/D] [drive:][path]
    CD [..]
    
      ..   Specifies that you want to change to the parent directory.
    
    Type CD drive: to display the current directory in the specified drive.
    Type CD without parameters to display the current drive and directory.
    
    Use the /D switch to change current drive in addition to changing current
    directory for a drive.
    
    If Command Extensions are enabled CHDIR changes as follows:
    
    The current directory string is converted to use the same case as
    the on disk names.  So CD C:\TEMP would actually set the current
    directory to C:\Temp if that is the case on disk.
    
    CHDIR command does not treat spaces as delimiters, so it is possible to
    CD into a subdirectory name that contains a space without surrounding
    the name with quotes.  For example:
    
        cd \winnt\profiles\username\programs\start menu
    
    is the same as:
    
        cd "\winnt\profiles\username\programs\start menu"
    
    which is what you would have to type if extensions were disabled.
    I believe you needed to add the argument /D in order for it to have worked. If there are spaces, you also need to enclose them with quotes.

    So in your case, the command would have been:

    Code:
    CD /D "F:\FolderA\FolderB\Folder (gnc)\Tools"
    Some suggestions that I can give if you ever find yourself in a similar situation again.

    1. Check what application is causing the said folder to be locked in the first place. I personally use Process Explorer v16.02 to accomplish this.
    2. Boot to a Windows PE/Linux environment and delete the file from there. < This one is a bit more tedious to do than the one above. But it's nice if you find no other way to do it.

    Hope this helps.
    Last edited by oreo27; 09 Apr 2014 at 03:24. Reason: Completed Syntax of CD Command
      My Computer


  3. Posts : 1,002
    XP Pro (x86) | 7 HP (x86) & (x64) | 7 Pro (x64)
    Thread Starter
       #3

    Thanks oreo27 for such a prompt and detailed reply :)

    I will keep you posted on how it works out (a day or two)
    Would have been handy to still have the stubborn folder (in a way). In its place I am using a spare thumb-drive as the target drive instead of exposing the external data HD to a risk.
      My Computer


  4. Posts : 521
    Windows 7 Ultimate x64 Service Pack 1
       #4

    GrayGhost2 said:
    Thanks oreo27 for such a prompt and detailed reply :)

    I will keep you posted on how it works out (a day or two)
    Would have been handy to still have the stubborn folder (in a way). In its place I am using a spare thumb-drive as the target drive instead of exposing the external data HD to a risk.
    No worries :) It sure would have been for testing purposes. Let us know how it goes :)

    Oh, and I almost forgot, to view any command's syntax from the command line, all one has to do is type "/?" at the end of said command. In your case, it would have been:

    Code:
    cd /?
    Helps a lot when something in CMD doesn't work out. Cheers.
      My Computer


  5. Posts : 126
    Windows 7 Pro 32bit / Windows 7 Professional
       #5

    In my network batch files, I simply type the drive letter. Once you are parked on that drive, then use the CD command to change directory. I store batch files in my User Name folder, and when the switch occurs in the batch file, the active directory is the top folder of the share on that computer (drive\Users\Public). To change directory from there you need to know the relative path from THERE to the folder in question.
      My Computer


  6. Posts : 1,002
    XP Pro (x86) | 7 HP (x86) & (x64) | 7 Pro (x64)
    Thread Starter
       #6

    Back to basics


    Hi Sundrance, thank you for your response :)

    This is my first experience with the cmd window, so I would appreciate any coaching.

    I tried ... C:\windows\system32>cd F:\Folder1 ... but the result is C:\windows\system32> ... again
    It is becoming obvious I am trying to put the cart before the horse.

    Looking to learn the basics of the cmd process I have done a duck-search:= "cmd.exe" ...
    Found CMD.exe Windows process - What is it? ... it looks promising, but then I don't really know what I am looking at.

    I would appreciate any pointers to where I can learn how to use the cmd window effectively and safely (and terminology)
    I found a tip to the concealed "menu" and settings. Already learnt how to paste into cmd window.

    Remove stubborn folder, on external drive, using cmd window-cmd-menu_1.png Remove stubborn folder, on external drive, using cmd window-cmd-menu_2.png

    What is the difference between ...
    Defaults ... "Console Windows Properties"
    Properties ... "C:\Windows\System32 - Properties" ... (as user and Administrator)

    Would "Defaults" be the template-of-settings ?

    Thank you :)
      My Computer


  7. Posts : 521
    Windows 7 Ultimate x64 Service Pack 1
       #7

    GrayGhost2 said:
    Hi Sundrance, thank you for your response :)

    This is my first experience with the cmd window, so I would appreciate any coaching.

    I tried ... C:\windows\system32>cd F:\Folder1 ... but the result is C:\windows\system32> ... again
    It is becoming obvious I am trying to put the cart before the horse.

    Looking to learn the basics of the cmd process I have done a duck-search:= "cmd.exe" ...
    Found CMD.exe Windows process - What is it? ... it looks promising, but then I don't really know what I am looking at.

    I would appreciate any pointers to where I can learn how to use the cmd window effectively and safely (and terminology)
    I found a tip to the concealed "menu" and settings. Already learnt how to paste into cmd window.

    Remove stubborn folder, on external drive, using cmd window-cmd-menu_1.png Remove stubborn folder, on external drive, using cmd window-cmd-menu_2.png

    What is the difference between ...
    Defaults ... "Console Windows Properties"
    Properties ... "C:\Windows\System32 - Properties" ... (as user and Administrator)

    Would "Defaults" be the template-of-settings ?

    Thank you :)
    What SundRance meant was this:

    If you want to change directories quickly, you can simply type in the drive letter. In your case, type

    Code:
    f:
    then hit enter. You can now browse the folders using the CD command directly. To use it, type

    Code:
    cd Folder1
    then hit enter. You need to put quotes before and after the folder if they have spaces. I normally just put them around any directory even if there are no spaces for good practice.

    Code:
    cd "Folder1"
    The shortcut would have been:

    Code:
    CD /D "F:\Folder1"
    then hit enter.

    I think that's a process overview for knowing what a certain exe does. You're better off reading something similar to this to get a basic idea of how to utilize this tool.

    I'm not familiar with the settings of command prompt but I believe this has something to do with customization.
      My Computer


  8. Posts : 126
    Windows 7 Pro 32bit / Windows 7 Professional
       #8

    Sorry, spent some time off line. So, the first thing to be aware of is what directory/folder are you in when the Command window opens? I place batch files in my Windows 7 user folder, that way, when I run 'CMD' from a run box the path reads: C:\User\My NAME. Knowing where you are is important if you are writing path statements in a command window. So, one of the typical things I do is run a backup batch file to copy files from my portable to my desktop computer. When mapping my network drive I always make sure the desktop maps to 'Y'.

    Knowing how you have the network resource 'Shared' is also important. I share the 'Public' folders on my desktop computer so in the command window of my portable when I type 'Y:' the path in the command window shows 'Y:' and is actually the C:\Users\Public folder of my desktop.

    Knowing the command prompt 'Y:' is the Users\Public folder on my desktop, I can change to the 'Documents' folder of my desktop with the command, 'CD Documents'. The batch file might read:

    @echo off

    Y:
    cd\Documents
    Copy C:\Users\MY NAME\*.* .

    The copy command will grab all of the files in my private name Documents folder on my laptop to the public documents folder of my desktop. Since the command window is open at Y:\Documents (desktop computer \Users\Public\Documents). The dot at the end of the copy statement is just used to say, here.

    My advice is to play around in the Command window without trying to copy or move files. Once you learn how to navigate around your network you can write in the command that will do your lifting. You can write a batch program that just navigates through your network and pauses, and then you'll know you have the path statements right.

    You could seriously mess up if you delete something in Command by accident.

    Let me know if I've just confused you more or if I can help some more. I am not all that versed, but starting out in the early days of Windows, I did learn a few DOS basics.

    Be Well,
    RȘnce
      My Computer


  9. Posts : 10,485
    W7 Pro SP1 64bit
       #9

    GrayGhost2 said:
    ~~~
    What is the difference between ...
    Defaults ... "Console Windows Properties"
    Properties ... "C:\Windows\System32 - Properties" ... (as user and Administrator)

    Would "Defaults" be the template-of-settings ?

    Thank you :)
    Yes - pretty much.

    The other "Properties" dialog box is tied to the title of the command prompt that is open at the time.

    It is true that you can get to these property settings by clicking in the upper left corner, but you can also right click anywhere in the title bar too. I would suggest that you place a check by the option for the QuickEdit Mode. When you right click inside the command prompt window, it will paste from the OS clipboard to the cmd window. When you select text and then right click inside the command prompt window, it will copy text from the cmd window to the OS clipboard.

    Hopefully you have discovered the up arrow and down arrow keys to repeat what was entered before. If you make a typo, press the up arrow key one time - then use the left arrow key to get to the location of the typo.

    I watched most of the video where the person was showing how to get rid of a folder named "problem folder" on the desktop. I see no reason to change the working folder of the command prompt window just to do the steps shown. Nor is there a need for a space between switches.

    C:\Windows\system32>dir c:\users\username\desktop /a/x/p

    I find typing to be dangerous. I tend to copy/paste... even in a cmd prompt window.

    For non-elevated cmd windows, you can drag a folder from the Windows (file) Explorer window into the cmd prompt window and the path to that folder is automatically added (if using the QuickEdit Mode).

    For elevated cmd windows, you can shift+right-click on the folder of interest and select "Copy as path" before pasting it into the cmd prompt window.

    Both of those methods automatically add quotation marks around a path when needed.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 13:02.
Find Us