Vim using gf with spaces in filenames - windows

In gVim if the cursor is over a filename (like "C:\Program Files\Vim\vim71\README.txt" ) which contains spaces then using 'gf' fails.
I found the isfname option but the documentation says one should avoid using spaces.
Is there I can make gVim open files under these circumstances ?

You can select text in visual mode and then do a gf on it, that get's round the problem to some extent.

Another option is to use Windows' "8dot3" filenames. I've tested it out in Windows 7 + GVIM succesfully.
Find out the short filename by using the /X flag in the CMD prompt. You want to CD to the parent folder to that which has spaces in it. I'm not sure how to get the whole path at once in "8dot3" form.
Typing "cd " and then dragging from the Explorer's address bar to the CMD window can be easier than typing out the path:
> cd "C:\Users\Fabrice\Documents"
> dir /X
Then use it in Vim, eg:
C:\Users\Fabrice\Documents\MYGAME~1\Skyrim\SkyrimPrefs.ini
If using a folder instead of a file name, the path appears properly expanded in the Netrw listing (:Ex file list).

Related

How to open the command prompt from a file

For quick access to the command prompt pointing to a specific directory, I would like to double click on a .bat file (saved on the desktop), and then the command prompt will open pointing to a specific folder, and would like the command prompt to remain open.
This is what I did:
rem -changing the drive to e:
e:
rem - setting the path to the specific folder
cd \users\myName\Documents\folderName\folderName\folderName\
==> this results on the command prompt opening in the specify directory, but closing right away.
I have no problem opening in the 'e' drive (start cmd e: ), but when I specify the path to the folder, it does not work
Is there a way to do this?
You need to use the option /K of the cmd.exe
Please take a look at the following link:
open command prompt window and change current working directory
Hope that helps,
The /K option is the key, as has been said. However, if you want a better CMD environment, considering creating shortcuts to CMD in a desktop folder. By changing the properties of each shortcut, you can then customize the environment, window size, fonts, buffers, etc.
To do this, create a shortcut with a Target something like this:
%windir%\system32\cmd.exe /K C:\Batch\your_batch_file.bat
In your_batch_file.bat, you can set environment variables, paths, select the drive, set the working directory, etc.
By changing the properties of the shortcut, you can totally customize the window size, fonts, colors, buffers, etc.
I use this to set up separate environments for Ruby, JRuby, CMD, etc.
The shortcut properties looks something like :
#echo off
cd /d "e:\users\myName\Documents\folderName\folderName\folderName\"
cmd /k
exit

DOS start command does open directory with spaces

Help please..
I wanted to Open the copied file folder once the file has been copied.
I used DOS command start. It works fine as long as the directory path does not contain any space characters.
If I use quotes in the path it rather opne another dos screen:
**Here sample CMD file:
XCopy C:\1\Source\Test.txt C:\1\Target 1\ /R/Y/K
start "C:\1\Target 1\"
Pause**
You had the right idea with the quotes. The tricky bit is that start assumes the first parameter is the window title if it is quoted. If you want to quote your target then you must provide a quoted title first. It can be empty:
start "" "C:\1\Target 1\"
However, if you happen to have a batch file named Target 1.bat, then it will execute the batch script instead of opening the Target 1 folder in Windows Explorer. For that reason, it is safer to use robert oh's answer, explicitly specifying explorer as the target with the folder as a parameter.
You could use
start explorer "c:\some folder\"

Windows CMD: How to create symbolic link to executable file?

My goal is to add a few executables to my PATH (for example, chrome), so that I can call
> chrome
from the command prompt and it will launch Chrome.
I know I could add Chrome's containing directory to my path (set PATH=%PATH%<chrome_path_here>;), but since I have a few executables I want to add, I'd rather make a new bin directory that contains symbolic links to the actual executables and just add that single directory to my PATH.
The Chrome executable is located at
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
So I tried
> mklink chrome.exe "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
That successfully creates a symbolic link for the files (says so in output, and upon examining with > dir). I know my PATH is set up correctly, b/c when I run > where chrome it finds my new symbolic link.
However, when I try to execute chrome with my new link, nothing happens. A new empty window should appear, but nothing happens. No error message in the command prompt or anything.
What am I doing wrong? Am I misunderstanding symlinks in Windows? This is the approach I use in Linux all the time, but I'm new to Windows Cmd.
Thanks!
Most programs will not run from places other than they install location - which is exactly what happens when you try to run it from symlink.
It would be much easier to create CMD/BAT files in that folder with matching names which will launch programs from locations you want:
REM chrome.cmd
start /b cmd /c "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" %*
With Windows 7 I confirm that symlinks do not work, are simply ignored as reported in the original question.
As Harry states in his comment, shortcuts do work, and to me are simpler and easier than writing a separate script for each new command I want to enable under CMD.
He states that you need to add .lnk to your PATHEXT variable in order to do this. I affirm that this does work, and with .lnk added to PATHEXT I can simply enter the name portion of the shortcut to run the command. For example if my shortcut is named "sublime.lnk" and PATHEXT includes .lnk, I can execute the link with the simple command "sublime". Nice!
As an alternative I found that PATHEXT need not be modified if I simply type in the full name of the shortcut, including the .lnk, at my CMD prompt. E.g., I created a shortcut named "sublime.lnk" under %HOMEPATH%/bin, pointing to "C:\Program Files\Sublime Text 2\sublime_text.exe".
Now by placing %HOMEPATH%\bin in my %PATH% I can run sublime via the command "sublime.lnk".
Either of the above are the best way I know of giving access to various commands from around Windows' filesystem from a CMD prompt. I'm not a Windows expert though, and welcome a better or more standardized solution to this problem.
P.S.: I just found out the hard way that you need to ensure the "Start in:" property of any shortcut you use in this fashion is blanked out, or your program will not start in the directory you invoke the shortcut from.
P.P.S.: On a related note, I discovered how to run Windows Explorer (or its replacement) on the directory your CMD session is logged in to: start ..

Sublime Text from Command Line

I installed Sublime Text and wanted to know how to open rb files in it from the terminal. I saw What is the command to make Sublime Text my core editor? and I see that I can make Sublime my core editor, but I want to be able to type
sublime file.rb
How do I do this in Windows?
Windows Command Prompt
For Windows cmd.exe you could just add the sublime text installation directory to your PATH environment variable, this would allow you to type:
sublime_text file.rb
Personally, I add a doskey (in a .bat file set to autorun with cmd) so I can type subl file.rb:
> doskey subl="C:\Program Files\Sublime Text 2\sublime_text.exe" $*
Cygwin
For the default bash shell add an alias to your ~/.bashrc file, e.g:
$ echo 'alias subl="/cygdrive/c/Program\ Files/Sublime\ Text\ 2/sublime_text.exe"' >> ~/.bashrc
From build 3065 (Release Date: 29 August 2014) onwards Sublime text includes a command line helper, nameley subl.exe. It is at sublime's installation folder: copy it in to a folder included in the system path.
For example, in my case I copied it
from C:\Program Files\Sublime Text 3
to C:\Windows\System32
You may then use in your terminal/console subl as a command to open whatever file, such as in your example:
subl file.rb
Or you may as well modify your system PATH variable to include sublime's instalation folder, but I believe that is much more involved.
I added this to my PowerShell profile:
Set-Alias subl 'c:\Program Files\Sublime Text\subl.exe'
Modify this as needed for Sublime Text 3 (or any future versions).
You also may read about profiles in built-in help:
Get-Help about_Profiles
Another idea would be to include C:\Program Files\Sublime Text 2\ in your PATH, and then run an administrator command prompt:
cd "C:\Program Files\Sublime Text 2\"
mklink sublime.exe sublime_text.exe
That will make a symbolic link with the new name. And now you can use it freely:
sublime hello.txt
Update: After having a chance to use this trick and update Sublime Text 2, I'm happy to say that updating to a new build doesn't affect the symbolic link.
Add the installation folder to windows path and you will be able to open Sublime by typing the name of the executable file, which is by default "subl".
To include the Sublime installation folder in windows path,
Open command prompt and type sysdm.cpl
In Advanced tab, select Environment variables
Under system variables, select variable named "Path" and click Edit.
Add "C:\Program Files\Sublime Text;" to the end of the existing string.
Save the changes and restart command prompt.
I've created subl.bat in C:\Program Files\Sublime Text 2 with contents:
start sublime_text.exe %*
Now that I have C:\Program Files\Sublime Text 2 in PATH, I can simply type 'subl folder' and it works wonderfully without having to add anything to autostart.
I think that is more easy set the Environment variable in Windows.
Then just add a new System variable called SUBLIME_HOME with value "C:\Program Files\Sublime Text 2\" (without quotes) after edit the variable Path adding in the end this value ";%SUBLIME_HOME%" (without quotes).
Restart the git BASH and enjoy, using like this:
$ sublime_text mi-new-file
(where sublime_text is the command)
Note: Also works now for cmd of Windows.
I know this thread is a bit old, but I recently came up with this solution and thought I would share it...
If you use Cygwin, you can create a bash script that will convert the unix pathnames to windows paths and pass them to sublime. Paste the following into a new file:
#!/bin/bash
/cygdrive/c/Program\ Files/Sublime\ Text\ 2/sublime_text.exe `cygpath -w $#` &
Save it in /usr/bin/subl (or wherever you want so long as the location is in your $PATH) and make it executable ($ chmod a+x /usr/bin/subl)
With this script, you can use both UNIX and Windows style paths (/cygdrive/c/ or C:/) because the cygpath utility converts the / and ~ path aliases to their windows equivalents.
Now, you can use $ subl file1.txt file2.md ~/file3.txt to open those files in sublime!
The accepted answer doesn't seem to work, at least for Sublime Text 3 on Windows 7. Copying the file directly into C:\Windows\System32 allows subl to resolve fine from the shell, but when I run it, nothing happens.
I've had more success with a hardlink:
mklink /h c:\windows\system32\subl.exe "c:\Program Files\Sublime Text 3\subl.exe"
With that, subl <file.txt> and subl <directory> both work fine.
I'm trying out ruby on rails in windows and include the PATH C:\Program Files\Sublime Text 2\,then change the name sublime.exe to subl.exe.
worked fine in regular cmd and "command prompt with ruby and rails" cmd
I just ran the Command Prompt program as an Administrator, and executed the following command.
Simple, but works for me.
echo "c:\Program Files\Sublime Text 3\subl.exe" %1 > %systemroot%\system32\subl.bat
Of course, you can call the bat file whatever you want. From then on, as any user you can simply use:
subl myfile.txt
I created a simple batch file (s.bat) in the windows directory to start sublime text
This is the code I put in the batch file to start Sublime Text 2
#start "sublime" "%ProgramW6432%\Sublime Text 2\sublime_text.exe" %*
I call sublime by typing
s
I directly open a file using
s filename.ext
If your using Cmder, you can add the alias to your aliases file, which is located wherever you installed cmder to, then config\aliases
You can then add ( this is for sublime text 3 )
subl="C:\Program Files\Sublime Text 3\sublime_text.exe" $1
From within Cmder, you can then open any directory in sublime via
subl="C:\Program Files\Sublime Text 3\sublime_text.exe" $1
try this:
alias subl='"/c/Program Files/Sublime Text 2/sublime_text.exe"'
make sure that the sublime install which directory.
It will create the alias for sublime then type:
subl file.rb
Going off the most accepted answer, but whose author unfortunately said modifying the PATH is "hard" - it's not at all. It's very easy. I just did it, and you can too!
Here's what to do:
Navigate to your sublime text directory in Windows Explorer and copy the full path from the path bar.
For example, I have a few development tools set up as portable applications in Dropbox, so I copied the path:
C:\Users\username\Dropbox\Programs\Sublime Text Build 3114 x64
Go to Control panel-> System-> Advanced System Settings-> Environment Variables
In the resulting window, navigate to "path" in the bottom window, highlight it and click "Edit".
In the window that appears, click "New", paste in your Sublime Text path, and click "OK".
Now open CMD or Powershell and type subl
Sublime Text window should open. Enjoy!
Note: I noticed someone else answered this in a similar fashion, but used a fixed location for Sublime Text. That may work for some people, but for others the directions will be erroneous. The fact is, the Sublime Text location can be anywhere on the drive, and knowing where it is and copying that particular location is one of the most important parts of assigning the PATH variable.
I wanted to start a new instance of Sublime Text from the command-line.. The following page helped me, even though it only says OSX: http://www.sublimetext.com/docs/3/osx_command_line.html.
So, I use a batch file in my user path to launch 'sublime'. Here is basically what I use (**the batch file contents):
#start "sublime" "%~dp0Sublime Text\sublime_text.exe" --new-window %*
(my batch file %~-dp0 is located one folder above the Sublime Text installation path.)
I know this is an old thread, but I thought I'd add what I was looking for (and found). It might help someone else!
Set the path for sublime:
My computer >> properties >> advanced setting >> environment variables >> path variable >> Add>> C:\Program Files\Sublime Text 3
Just go to directory where sublime is installed and rename sublime_text to sublime.
Open command prompt and type sublime.
You can simply install Notepad Replacer http://www.binaryfortress.com/NotepadReplacer/
what it will do is make sublime your default notepad in Windows and then you can simply use the commands that you generally use to open inbuilt notepad in windows. for example
`//to open test.txt, just type
notepad test.txt
//to open sublime, Type
notepad`
add Sublime's installation folder to your path.
#set PATH=C:\Program Files\Sublime Text 3;%PATH%
or
To set an environment variable permanently in Windows (so that it is available to all the Windows' processes),
start the "Control Panel" ⇒ "System" ⇒ (Vista/7/8) "Advanced system settings" ⇒ Switch to "Advanced" tab ⇒ "Environment variables" ⇒ Choose "System Variables" (for all users) or "User Variables" (for this login user only) ⇒ Choose "Edit" (for modifying an existing variable) or "New" (to create a new variable) ⇒ Enter the variable "Name" and "Value".
in that case prepend C:\Program Files\Sublime Text 3 to the path.
Now, can make a copy of 'sublime_text.exe' as 'sublime.exe'
Then in any command prompt you may be able to run a file.txt file by
C:\Users\MyUsername>sublime filename.txt
In the Environmental variable I added %SUBLIME_HOME% variable to the path variable as well
Then made a symbolic link from my Command terminal
mklink sb sublime_text.exe
create in registry:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\sublime.exe
update value of default parameter (REG_SZ) to:
C:\Program Files\Sublime Text 2\sublime_text.exe
This powershell allows me to pipe to the edit function (or to use it in the normal way)
function edit
{
param( [Parameter(ValueFromPipeline=$true,Position=0)] $file )
begin { set-alias EDITOR 'W:\tools\sublime_text.bat' }
process { EDITOR $file }
}
here is the sublime_text.bat which for some reason seems necessary (anyone know why?)
START "Sublime Text 2" "C:\Program Files\Sublime Text 2\sublime_text.exe" %*
Hollow every one.
I build a very easy way to do this.
project github page
just download "install.bat"
and right click on install.bat -> click "run as administrator"
If you don't want to change your path you can associate files with sublime. So right click on the file, click properties, then click opens with sublime text.
From the command line:
myFile.py
Will open the file in sublime. I suppose this saves you about five keystrokes.
#echo off
:: File: TextFiles.Starter.DESKTOP-M175NUE.cmd v1.1.0 docs at the end
:: this just an iso-8601 wrapper for windows:
:: src: http://www.cs.tut.fi/~jkorpela/iso8601.html
call GetNiceTime.cmd
:: go the run dir
cd %~dp0z
:: this is the dir containing the batch file
set _MyDir=%CD%
:: look around , set vars
for %%A in (%0) do set _MyDriveLetter=%%~dA
for %%A in (%0) do set _MyPath=%%~pA
for %%A in (%0) do set _MyName=%%~nA
for %%A in (%0) do set _MyEtxtension=%%~xA
:: contains absolute file paths of the files to open like this
set _ListFile=%_MyDir%\%_MyName%.lst
:: example of lines in the list file - take out the ::space
:: C:\Users\ysg\Desktop\TextFiles.Starter.DESKTOP-M175NUE.cmd
:: C:\Users\ysg\Desktop\TextFiles.Starter.DESKTOP-M175NUE.lst
:: set _Program="C:\Program Files\TextPad 8\TextPad.exe"
set _Program="C:\Program Files\Sublime Text 3\sublime_text.exe"
set _
:: DEBUG PAUSE
:: sleep 2
ping -n 2 www.google.com > NUL
:: for each line of the cat file do open
:: for TextPad , obs note the quoting
:: for /f "tokens=*" %%i in ('type "%_ListFile%"') do ^
:: cmd /c "%_Program% "%%i""
:: for sublime, obs note the quoting
for /f "tokens=*" %%i in ('type "%_ListFile%"') do ^
cmd /c "%_Program% -t "%%i""
:: DEBUG PAUSE
:: Purpose:
:: to start a list of non-binary files from a list file on Windows 10
:: Tested on Windows 10, should work on Win7 too
::
:: Requirements:
:: TextPad 8 or Sublime
::
::
:: Usage:
:: copy this file onto your Desktop, list the absolute paths in to the list file
:: change the program name in the _Program if if you want other editor
::
:: VersionHistory:
:: 1.1.0 --- 2017-10-06 09:42:54 --- ysg --- added sublime
:: 1.0.1 --- 2013-04-15 08:19:10 --- ysg --- added - todo-%today%.txt file opening
:: 1.0.0 --- 2012-05-23 09:08:57 --- ysg -- Initial creation
Here is what worked for me in PowerShell:
# CHECK IF YOUR ALIAS FOR SUBLIME TEXT 3 EXISTS
Get-Alias subl
# REMOVE YOUR ALIAS FOR SUBLIME TEXT 3 IF IT EXISTS
# REF 1
Remove-Item alias:subl
# SET YOUR ALIAS FOR SUBLIME TEXT 3
Set-Alias subl -Value "C:\Program Files\Sublime Text 3\sublime_text.exe"
# CREATE A TEST FILE ON YOUR Desktop
# REF 2
echo "Testing`nNew`nFile`n." > $HOME\Desktop\TestFile.txt
# TEST YOUR NEW ALIAS
subl $HOME\Desktop\TestFile.txt
This is the easiest way to set and test the alias. If you want to keep this against your profile try this:
# TO PERMANENTLY KEEP EVERYTIME YOU OPEN POWERSHELL PLEASE ADD TO YOUR PROFILE. BUT FIRST VERIFY YOUR PROFILE `FILE` EXISTS, IF NOT THEN THIS WILL CREATE IT.
# REF 3 & 4
if (!(Test-Path -Path $PROFILE.CurrentUserAllHosts)) {New-Item -ItemType File -Path $PROFILE.CurrentUserAllHosts -Force}
# open powershell PROFILE
ise $PROFILE.CurrentUserAllHosts
# Add the Set-Alias to your file
Set-Alias subl -Value "C:\Program Files\Sublime Text 3\sublime_text.exe"
REF 1 Remove-Alias: https://superuser.com/q/883914/247728
REF 2 Newline: https://stackoverflow.com/a/36738723/1896134
REF 3 https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-5.1
REF 4 https://devblogs.microsoft.com/scripting/understanding-the-six-powershell-profiles/
Operating System (OS): Windows 10 Pro
Windows ONLY: How to open -a “Sublime Text” in windows?
Assuming your Sublime Text 3 was located in the "C:\Program Files\Sublime Text 3" directory
In Git Bash copy paste and run:
echo 'alias subl="/C/Program\ Files/Sublime\ Text\ 3/sublime_text.exe"' >> ~/.bashrc
Close Git Bash and Open it again.
In Git bash type:
subl
go to enviroment and add sublime text folder to system path directory , dont add anything to system 32 directory it's just making a mess ,after that you can type
''' subl mytext.txt ''' in cmd.
Add the installation folder to windows path.
- Click on windows button
- Type advance system settings in search box
- Click on the result (View Advance System Setting)
- Click on the Environment Variable Button at the Bottom right
- Go to System Variable Section Second
- Search for Path
- Click on Path and Click on Edit Button
- Click on New on right sidebar
- Copy the Folder Path of Sublime Text Editor Sample(C:\Program Files\Sublime Text 3)
- Paste on New Line on Environment Variable
- Click on OK on Every Dialog Box
- All Set Now Follow below Steps
Close the CMD if Open or just start new CMD.
Go to your project folder.
Click on the Address line in Windows File Explorer.
Select all and type CMD.
It will open the project folder in CMD.
Then just type subl . //don't forget to add the
dot (.) after (subl) ex (subl .)
All done, it will open the project in sublime text editor.
After trying for a long time, the following steps worked for me.
Create a PowerShell profile
Use the following command:
if (!(Test-Path -Path )) {
New-Item -ItemType File -Path $PROFILE.CurentUserAllHosts -Force
}
Edit the profile
You can open any PowerShell profile in a text editor, such as Notepad.
To open the profile of the current user in the current PowerShell host
application in Notepad, type:
>notepad $PROFILE.CurentUserAllHosts
On notepad, paste the following command in the profile file
Set-Alias subl -Value "C:<the path of the sublime_text.exe on your PC"
To apply the changes, save the profile file, and then restart PowerShell.
Now on Powershell, cd the directory of your choice and type:
subl .
e.g,
$newfile subl .

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