Unable to delete a windows folder? - windows

There are quite a lot of suggestions to be found whilst searching but none had worked for us, (most likely because the folder name appeared to be appended with a (weird?) blank character which we also could not rename or delete). The folder properties security tab showed no information only errors. Various tools provided no info on the folder for us.

In file explorer navigate to the parent folder
Open a command prompt: Dir /X
in our case the problem folder then ended with ~1
ren shortname~1
del shortname~1

Related

Maria DB change datadir on windows server

I installed MariaDB on my windows server and saw it defaults the datadir where the databases are stored to C:\Program Files\MariaDB 10.2\data
I wanted it moved the the E: disk that's dedicated to database stuff.
I thought copying the datadir and then modifying the my.ini in the C:\Program Files\MariaDB 10.2\data datadir would solve it, but when I tried to restart the service it wouldn't start.
I also tried setting the folder permissions to network service but that didn't seem to help.
What do I have to do to move my datadir on windows?
After a lot of searching I stumbled across http://baazgusht.blogspot.nl/2017/02/change-datadir-of-mariadb-in-window.html
It gave me the hint I needed to move the datadir on windows.
open cmd in administrator mode(start search cmd, rightlick execute as administrator)
type Net stop MariaDB (or whatever you named your service. for me it was net stop "MariaDB 10_2_7"
CD to C:\program files\mariadb 10.2\(or wherever your mariadb is installed)
Type: xcopy data E:\MariaDB /O /X /E /H /K (E:\MariaDb is my location, you may have another location. replace E:\MariaDB with whatever you want, just use the same value below for the datadir in my.ini)
Xcopy will ask when the destination doesn't exist if it should be a file or a folder. Choose the option that represents Folder.
Type: notepad data/my.ini
change the value of datadir=C:\Pro.... to datadir=E:\MariaDB
save (ctrl + s)
in CMD type net start mariadb (or whatever you named your service. for me it was net start "MariaDB 10_2_7"
I think that real problem is this one.
MariaDB use MySQL5.5 (or MariaDB10 for other version I use) as "group user" to set full permission on data folder. But this "group user" is not create under Windows "users and groups". So you cannot add this group on security tab and set permission to another folder.
Effectively, the workaround is to xcopy the original data folder to new location preserving the original permission.
But my problem is that I recover after a crash an older data folder. So it's not clear that workaround work (I wil try it tonight). I need to set the correct user group.
A true bug fix: fix intallation of MariaDB to effectivily create the "group user" in right place not just use it in folder permission.
Additional information to #Tschallacka's answer:
The copied my.ini file should be deleted from the target directory ("E:\MariaDb" in their example), since it is not honored by MariaDB. (It still contains the old path anyways.) And the contents of the source directory ("C:\Program Files\MariaDB 10.2\data" in their example) except my.ini should be deleted too, since those files are now found at the new path.
#Tschallacka's solution works because xcopy also copies permissions of the files. Windows Explorer does not.
Explanation of the options for xcopy:
/E Copies directories and subdirectories, including empty ones.
/H Copies hidden and system files also.
/K Copies attributes. Normal Xcopy will reset read-only attributes.
There are no hidden, system or read-only files in there right after install and there shouldn't after normal use and it shouldn't matter for the copied files, but it won't hurt.
/O Copies file ownership and ACL information.
The original directory has some additional permissions set. Without those, the MariaDB service seems to not be able to access the copied files properly.
/X Copies file audit settings (implies /O).
The service seems to start fine even without this option.
After some confusion with this error I can recommend that you:
Use slashes in Windows paths, for example C:/MariaDB/DB.
Experiment with adequate permissions. This seems to work:
cacls Path_to_MariaDB_DBData /E /T /P "Network Service":F

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 to run batch file from network share without "UNC path are not supported" message?

I am trying to run a batch file from a network share, but I keep getting the following message: "UNC path are not supported. Defaulting to Windows directory." The batch file is located on \\Server\Soft\WPX5\install.bat. While logged in as administrator, from my Windows 7 Desktop, I navigate to \\Server\Soft\WP15\ and double click on install.bat, that's when I get the "UNC path are not supported." message. I found some suggestions online stating that mapping drive will not work, but using a symbolic link will solve this issue, but the symbolic link didn't work for me. Below is my batch file content, I would appreciate any assistance that can help me accomplish what I am trying to do. Basically, I want to be able to run the batch file from \\Server\Soft\WP15\install.bat.
Batch file content
mklink /d %userprofile%\Desktop\WP15 \\server\soft\WP15
\\server\soft\WP15\setup.exe
robocopy.exe "\\server\soft\WP15\Custom" /copyall "C:\Program Files (x86)\WP\Custom Templates"
Regedit.exe /s \\server\soft\WPX5\Custom\Migrate.reg
Also, how do I remove the symbolic link after the install is completed?
PUSHD and POPD should help in your case.
#echo off
:: Create a temporary drive letter mapped to your UNC root location
:: and effectively CD to that location
pushd \\server\soft
:: Do your work
WP15\setup.exe
robocopy.exe "WP15\Custom" /copyall "C:\Program Files (x86)\WP\Custom Templates"
Regedit.exe /s WPX5\Custom\Migrate.reg
:: Remove the temporary drive letter and return to your original location
popd
Type PUSHD /? from the command line for more information.
I feel cls is the best answer. It hides the UNC message before anyone can see it. I combined it with a #pushd %~dp0 right after so that it would seem like opening the script and map the location in one step, thus preventing further UNC issues.
cls
#pushd %~dp0
:::::::::::::::::::
:: your script code here
:::::::::::::::::::
#popd
Notes:
pushd will change your working directory to the scripts location in the new mapped drive.
popd at the end, to clean up the mapped drive.
There's a registry setting to avoid this security check (use it at your own risks, though):
Under the registry path
HKEY_CURRENT_USER
\Software
\Microsoft
\Command Processor
add the value DisableUNCCheck REG_DWORD and set the value to 0 x 1
(Hex).
Note:
On Windows 10 version 1803, the setting seems to be located under HKLM:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor
Basically, you can't run it from a UNC path without seeing that message.
What I usually do is just put a CLS at the top of the script so I don't have to see that message. Then, specify the full path to files in the network share that you need to use.
I needed to be able to just Windows Explorer browse through the server share, then double-click launch the batch file. #dbenham led me to an easier solution for my scenario (without the popd worries):
:: Capture UNC or mapped-drive path script was launched from
set NetPath=%~dp0
:: Assumes that setup.exe is in the same UNC path
%NetPath%setup.exe
:: Note that NetPath has a trailing backslash ("\")
robocopy.exe "%NetPath%Custom" /copyall "C:\Program Files (x86)\WP\Custom Templates"
Regedit.exe /s %NetPath%..\WPX5\Custom\Migrate.reg
:: I am not sure if WPX5 was typo, so use ".." for parent directory
set NetPath=
pause
Instead of launching the batch directly from explorer - create a shortcut to the batch and set the starting directory in the properties of the shortcut to a local path like %TEMP% or something.
To delete the symbolic link, use the rmdir command.
I ran into the same issue recently working with a batch file on a network share drive in Windows 7.
Another way that worked for me was to map the server to a drive through Windows Explorer: Tools -> Map network drive. Give it a drive letter and folder path to \yourserver. Since I work with the network share often mapping to it makes it more convenient, and it resolved the “UNC path are not supported” error.
My situation is just a little different. I'm running a batch file on startup to distribute the latest version of internal business applications.
In this situation I'm using the Windows Registry Run Key with the following string
cmd /c copy \\serverName\SharedFolder\startup7.bat %USERPROFILE% & %USERPROFILE%\startup7.bat
This runs two commands on startup in the correct sequence. First copying the batch file locally to a directory the user has permission to. Then executing the same batch file. I can create a local directory c:\InternalApps and copy all of the files from the network.
This is probably too late to solve the original poster's question but it may help someone else.
This is the RegKey I used:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor]
"DisableUNCCheck"=dword:00000001
My env windows10 2019 lts version and I add this two binray data ,fix this error
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor DisableUNCCheck value 1
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Command Processor
DisableUNCCheck value 1
This is a very old thread, but I still use Windows 7. :-)
There is one point that no one seems to have taken into account, which probably would help Windows 10 users also.
If Command Extensions are enabled, the PUSHD command accepts network paths in addition to the normal drive letter and path.
So the obvious - and simplest - answer might be to enable command extensions in the batch script, if you intend to use PUSHD. At the very least, this ought to reduce the problems you might have in using PUSHD wqith a network path.
I stumbled upon this question while searching for a solution to a specific problem. I needed to make a batch script that sits in a network folder (UNC path) with a Python script. The goal was to be able to double click on the batch script and have it run the Python script:
with the network folder containing the script as the working directory,
without modifications to the Python script (no command line parameters or hard-coded paths).
without creating another Python file.
The pushd and popd solutions were unsatisfactory. They work, but if the user were to get in the habit of forcefully terminating the script while it was running, they would end up with a bunch of mapped drives in My Computer since popd wasn't run.
I start by using cls to clear the UNC path error. I then assign the path containing the batch script to a variable. I slice the path to remove the trailing backslash (otherwise, Python throws a SyntaxError). Finally, I run a couple Python commands inside the batch file that change the working directory and execute the target script:
cls
#echo off
set pyfile=myscript.py
set batchdir=%~dp0
set wdir=%batchdir:~0,-1%
python -c "import os; import runpy; os.chdir(r""%wdir%""); runpy.run_path(r""%pyfile%"")"
pause
Editing Windows registries is not worth it and not safe, use Map network drive and load the network share as if it's loaded from one of your local drives.

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

Only Name File with Extension in Windows

I am trying to create a file in Windows XP that is only the extension (".classpath" and ".project"). While my Linux box handles this appropriately, Windows gives me the error, "You must type a file name."
Any suggestions how to do this? I am attempting to setup an Eclipse project where I can bring in the classpath and project files from someone else's setup and I keep getting the above error.
Just name your file with additional dot at the end: ".ext."
explorer will remove additional dot and you'll get .ext file.
use the commandline to do this, windows explorer doesn’t allow renamed files to start with a period. first create the file/directory with a dummy name x.ext, then fire up cmd.exe and rename it:
ren x.ext .ext
this way you can also create directories which names start with a period (like .git or .meta)
From the command line:
echo some text > .classpath
Windows seems not to be in control of how Save dialogs handle forbidden characters
Quoting the filename should do the job.
I have no Windows machine to try it out but I was able to save a ".htaccess" file in Notepad this way.

Resources