Folder is not deleting. How to delete this folder? - windows

See image here ->
I am trying to delete "Games" folder. Folder size is huge. But it's not deleting. Even not showing a message.
If I try to delete using cmd. But it shows another error:
See image here ->
What should I do now?

I have used " chkdsk D: /f " this command and it made that folder removable.

To remove a folder or anything from within the command prompt you have to use the word "del than the folder or file name" and not rm that is a unix command. Since your in Windows you could just right click on the folder in the file explorer and click on delete from the context menu.

Related

How can I open command prompt in the current directory as a shortcut

I'm just wondering how I can make a shortcut that will open command prompt in the folder it is currently in.
Why I need this.
I save my c program file in the directory Users\PC\Documents\Other\My_Programs\WIP\Project_1\Test\
So I would have to type cd Users\PC\Documents\Other\My_Programs\WIP\Project_1\Test\ every time I want to open the command prompt in that directory.
Is there a shortcut I can make where I can move that shortcut around anywhere (don't need to change the shortcut) and it will open command prompt in the directory it is current in, so I don't need to keep typing cd .....
you can go to the directory and just type start . in the same directory
or you can make a batch file like test.bat and add below line in the same:
cd Users\PC\Documents\Other\My_Programs\WIP\Project_1\Test\
Save it anywhere and whenever you will run that batchfile, it will automatically move PWD to the required directory
Right-click in the open space of your desktop and click New > Shortcut
For the location, type or copy and paste one of the following lines.
%windir%\system32\cmd.exe /k cd Users\PC\Documents\Other\My_Programs\WIP\Project_1\Test\
As commented by aschipfl, you can already do it, (may be OS dependent)!
In Windows Explorer, or I suppose the desktop, just hold down the shift key, right click in a blank area of it and choose Open command window here, (or whatever your locale states).
I think in Windows 10 at least, the option is even available in the Explorer toolbar menu too.

The System cannot find the file specified error while deleting folder

Hi can some one suggest me how to delete below folder(abc) using a batch file?
%UserProfile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\abc
I tried like RD %UserProfile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\abc /Q /S
But it is not deleting and when I execute the same command in command line it is giving a message like "The System cannot find the file specified" even though it is exists.
Any solution?
I used "rm -rf PATH_TO_FOLDER" command line on Git Bash (not cmd), then I can delete the similar folder.
Note: Tested on Windows 10 (latest version).
Use 7-zip to "move" them.
When facing an inability to delete a file because of "the system cannot find the file specified" I've tried all the common tricks (verify permissions, command line, free unlocker tools, etc).
What finally got rid of them for me was 7-zip. Using 9.20 "7-zip File Manager" interface (not just the right click on file options) I was able to "Move" the folder which contained the problem files. Sure, that just moves the problem but there is the beauty, you move them to a disk you can format: a VMDK, a thumb drive, etc... problem solved ;)
Inspired by one of the answers, but instead of using 7-zip I used WinRAR to archive the empty folder. Before archiving the folder there is an option to delete the folder after archiving, select that option and once the folder is a zip file, the folder should be deleted, and you can go ahead and delete the zip file. I am not sure if it will work for you but it worked for me after spending hours on the internet trying to find a solution.
Here is what worked for me.
Open command prompt
Browse to parent directory of the folder you want to delete
run 'dir /x' (displays short names - xxxxxx~1)
run 'rd xxxxxx~1' substituting the folder name you want to delete.
I had a problem where two Pictures folders would show under my user profile, and windows wouldn't let me delete the second folder.
Try putting the directory name in quotes:
rmdir /q /s "%UserProfile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\abc"
Otherwise the spaces in the directory name will be interpreted as argument separators.
The only solution that worked for me was to put \\?\ in front of the path when running rd in command prompt.
For example, to delete D:\bad\folder
Open CMD and then type:
rd /s "\\?\D:\bad\folder"
At a command line run:
ECHO %UserProfile%
What does it return?
Open that directory in Windows Explorer and double check that a folder called AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\abc exists in it.
I'm thinking that maybe it doesn't exist, and the folder you're looking at that you said does exist, is in a directory with a root that is different from %UserProfile%.
Update
Open a new command window by doing the following, which ensures that it's in Administrator mode.
On a Shortcut to a command window, Right Click > Properties > Shortcut > Advanced and check the "Run As Administrator" checkbox, and click OK twice. Then run the command prompt via the shortcut. You'll know it worked if it looks like this, with the word "Administrator" in the title, see screenshot below. Then try running your RD command again.

How can I change the icon of the %SystemRoot% folder (C:\Windows)?

I am trying to change the icon that shows for the System Root, C:\Windows. I can't customize it like you normally would a Windows folder. I have looked for a registry entry I could add a DefaultIcon key too, but I haven't found anything.
I have tried using a desktop.ini file to do it, but it won't work:
[.ShellClassInfo]
IconResource=icon.ico,-0
The desktop.ini file and that icon were both in the Windows directory and it didn't change it, but those same pieces worked fine in the Downloads folder, so the code works.
Whatever the solution, I would like to avoid using any program to accomplish this.
I also would like to add a custom Icon to the "Program Files" folder and encounter the same issues.
Edit: I assumed, but in case there is a question: I am running Windows 7 (32 Bit)
Just copy the desktop.ini file into C:\WINDOWS like you did, then run Command Prompt as Administrator to type below command.
ATTRIB +R C:\WINDOWS

BAT file to open CMD in current directory

I have many scripts which I interact with from the command line. Everytime I need to use them, I have to open a command line window and copy+paste and CD to the path to the directory they are in. This is tedious (they are in a rather deep file system, so typing out the full path is a pain, copy+paste is better but not much). I tried to create a .BAT file that I could double-click on that would open a new command-line window in the folder the .bat file exists in but it does not work. It opens a new window, but the working directory is not the directory that .bat file is in. Here's what I've got after much googling (My cmd skills ain't so great):
cd %CD%
cmd.exe
I know from when I used Linux that Konqueror had a "Command-line window here" feature, and that's the effect I'm trying to get on Windows.
you probably want to do this:
cd /d %~dp0
cmd.exe
this will set your current directory to the directory you have the batch file in
Create a file named open_dos_here.cmd with the following lines:
%~d1
cd "%~p1"
call cmd
Put this file at any folder.
Then, go to your Send To folder (Win+E; Alt+D;shell:sendto;Enter).
Create a shortcut to point to this open_dos_here.cmd
Then, in any folder, select any file or sub-folder. Right-click and select "Send To" and then select open_dos_here.cmd to open the DOS in that folder.
You can just enter cmd into the address bar in Explorer and it starts up in that path. Likewise for PowerShell.
There's a simpler way -
start /d "folder path"
As a more general solution you might want to check out the Microsoft Power Toy for XP that adds the "Open Command Window Here" option when you right-click: http://www.microsoft.com/windowsxp/downloads/powertoys/xppowertoys.mspx
In Vista and Windows 7, you'll get that option if you hold down shift and right-click (this is built in).
I'm thinking that if you are creating a batch script that relies on the Current Directory being set to the folder that contains the batch file, that you are setting yourself up for trouble when you try to execute the batch file using a fully qualified path as you would from a scheduler.
Better to add this line to your batch file too:
REM Change Current Directory to the location of this batch file
CD /D %~dp0
unless you are fully qualifying all of your paths.
Another solution is to use a shortcut file to cmd.exe instead of a batch file.
Edit the shortcut's start in property to %~dp0.
You achieve the same thing, except it has the Cmd icon (and you can change this).
Some people don't like clicking on batch files without knowing what's in them, and some corporate network drives have a ban on .bat files...
The simplest command to do this:
start
You can always run this in command line to open new command line window in the same location. Or you can place it in your .bat file.
Most simple way in explorer is to Shift + right mouse click on the folder or on an empty space in the folder and click on Open command prompt here.
CMD will then start in that folder
I must say, I'm not sure if it works for Windows Vista and below, but it surely works for Windows 7, 8, 8.1 and 10.
Referring to answer of #Chris,
We can also go to parent directory of batch file and run commands using following
cd /d %~dp0..
<OTHER_BATCH_COMMANDS>
cmd.exe
To understand working of command cd /d %~dp0.. please refer below link
What does it mean by command cd /d %~dp0 in Windows
You could add a context menu entry through the registry:
Navigate in your Registry to
HKEY_LOCAL_MACHINE/Software/Classes/Folder/Shell
and create a key called "Command Prompt" without the quotes.
Set the default string to whatever text you want to appear in the right-click menu.
Create a new key within your newly created command prompt named "command," and set the default string to
cmd.exe /k pushd %1
You may need to add %SystemRoot%\system32\ before the cmd.exe if the executable can't be found.
The changes should take place immediately. Right click a folder and your new menu item should appear.
Also see http://www.petri.co.il/add_command_prompt_here_shortcut_to_windows_explorer.htm
When you are in the desired folder , just type CMD in your address bar
A bit late to the game but if I'm understanding your needs correctly this will help people with the same issue.
Two solutions with the same first step:
First navigate to the location you keep your scripts in and copy the filepath to that directory.
First Solution:
Click "Start"
Right-click "Computer" (or "My Computer)
Click "Properties"
On the left, click "Advanced System Settings"
Click "Environment Variables"
In the "System Variables" Box, scroll down and select "PATH"
Click "Edit"
In the "Variable Value" field, scroll all the way to the right
If there isn't a semi-colon (;) there yet, add it.
Paste in the filepath you copied earlier.
End with a semi-colon.
Click "OK"
Click "OK" again
Click "OK" one last time
You can now use any of your scripts as if you were already that folder.
Second Solution: (can easily be paired with the first for extra usefulness)
On your desktop create a batch file with the following content.
#echo off
cmd /k cd "C:\your\file\path"
This will open a command window like what you tried to do.
For tons of info on windows commands check here: http://ss64.com/nt/
Create a new file startCmdLine.bat in your directory and put this line in it
call cmd
That is it. Now double click on the .bat file. It works for me.
You can replace call with start, it will also work.
this code works for me
name it cmd.bat
#echo off
title This is Only A Test
echo.
:Loop
set /p the="%cd%"
%the%
echo.
goto loop
you can try:
shift + right click
then, click on Open command prompt here
Inside given folder click on the top Adddress Bar and type cmd and click enter
It will open command prompt with current folder address.
You can simply create a bat file in any convenient place and drop any file from the desired directory onto it.
Haha. Code for this:
cmd

How to delete a folder that name ended with a dot (".")?

I got some folders created by malware whose name ended with a dot like C:\a.\ or C:\b.\, etc.
I found a solution that can remove such folder with command rd /q /s "C:\a.\" but if I call win API RemoveDirectory, it returns ERROR_FILE_NOT_FOUND.
And I just wonder how to write a function to delete such directory, thanks
I test on my own Windows XP SP3 system like this
create a folder C:\>mkdir a..\\\ and I cannot double click to access this folder. and I can remove with command rd /q /s "C:\a.\"
what Windows system API(s) that rd /q /s command call?
Here's a solution to this problem:
rd /s "\\?\C:\Documents and Settings\User\Desktop\Annoying Folder."
Solution:
When you call RemoveDirectory, make sure that you prefix the path with the string "\\?\".
Explanation:
It has everything to do with the dot. According to MSDN, there are certain cases where you may not be able to delete a file or folder on an NTFS volume, specifically when the file name is invalid in the Win32 name space (which is why you are unable to open the file using the normal methods in Windows Explorer).
You may not be able to delete a file if the file name includes an invalid name (for example, the file name has a trailing space or a trailing period or the file name is made up of a space only). To resolve this issue, use a tool that uses the appropriate internal syntax to delete the file. You can use the "\\?\" syntax with some tools to operate on these files, for example:
del "\\?\c:\path_to_file_that contains a trailing space.txt "
The cause of this issue is similar to Cause 4. However, if you use typical Win32 syntax to open a file that has trailing spaces or trailing periods in its name, the trailing spaces or periods are stripped before the actual file is opened. Therefore, if you have two files in the same folder named "AFile.txt" and "AFile.txt " (note the space after the file name), if you try to open the second file by using standard Win32 calls, you open the first file instead. Similarly, if you have a file whose name is just " " (a space character) and you try to open it by using standard Win32 calls, you open the file's parent folder instead. In this situation, if you try to change security settings on these files, you either may not be able to do this or you may unexpectedly change the settings on different files. If this behavior occurs, you may think that you have permission to a file that actually has a restrictive ACL.
(Source: http://support.microsoft.com/?kbid=320081)
Ive posted this on SU and I decided to post it here too. Its the simplest and fastest and easiest way to achieve this. I am now laughing at how much simple it is.
Install WinRAR
Follow the Step by Step procedure from pictures:
I myself had WinRaR installed so I decided to demonstrate the workaround in it.
This workaround is also possible by using 7zip.
One another thing I should mention is that, as it seems the problem is caused by using windows explorer and any other file browser (like winrar file browser itself, ftp explorers etc.) will treat this files as normal.
You could try using any file browser and simply delete those files and not bother archiving them though!
Cheers!
If you have git installed (you can get ir from here) then it is as simple as:
Navigate File Explorer to location where problematic folder is located.
Context menu (right mouse button) > Git Bash Here.
rm -rf Foldername./
When you see the name is "a.", but the actual name is "a.."
Try this:
rd /q /s "C:\a..\"
And you can try explore the folder by this code:
for /f "tokens=3 delims=<>" %%a in ('dir /ad /x "C:\*" ^| findstr " a\.\.$"') do (
for /f "tokens=1" %%b in ("%%a") do start "" "%%~fb"
)
I used "WinRar" A simple RAR, ZIP processor. You can use any sort of file name editor. Just open the directory where your file is into WinRar and select rename after right clicking the file/folder you want to rename and fill in the new name.
If you need to keep the data you can also use the \\?\ trick for renaming the folder.
ren "\\?\C:\Documents and Settings\User\Desktop\Annoying Folder." "\\?\C:\Documents and Settings\User\Desktop\Annoying Folder"
This is an ideal solution if you need to know what is inside the folder or if the data is important.
This works in both Command Prompt and PowerShell.
Try to use unlocker program to delete files and folders that you can't delete normally.
if you want to keep the files theres options in bash as well.
you will require the Windows Subsystem for Linux package (i have Ubuntu installed)
to keep the files. open a command prompt and cd over to where the file or folder is located.
now type "bash"
this will open bash in the prompt. now enter mv '[folder or file you want to move]' '[new name (can include path)]' (theres more to mv so if you want to read up on all of its options use 'man mv' this will open its manual page (then use q to return to bash))
the mv command is short for move, but its has a secondary function of renaming things.
also in bash use 'single quotes' and not a normal "double quote", as bash expects 'single quotes'.
heres a example. assume your folder is named "data 1." located in c:\users (so the full path to the error folder is c:\users\data 1.
1. open command prompt using any method
2. enter cd c:\users
3. now type bash this loads bash in the folder you previously were in
4. finally type mv 'data 1.' 'data 1'
5. the folder is now accessible and you can choose to delete it.
Use bash rm command from Ubuntu on Windows 10

Resources