How Should Everything Handle file with a final dot or period

General discussion related to "Everything".
Post Reply
therube
Posts: 5058
Joined: Thu Sep 03, 2009 6:48 pm

How Should Everything Handle file with a final dot or period

Post by therube »

How Should, or Should Everything Handle file names with a final dot or period?

BRU: Renaming file with final dot or period


As it is, Everything has no problem finding them.

Code: Select all

regex:^.*\.$
But after that... delete, copy, move, rename, inline-rename... all fail.

Hmm... I did not try UNC paths here... nope, that didn't work either.
NotNull
Posts: 5517
Joined: Wed May 24, 2017 9:22 pm

Re: How Should Everything Handle file with a final dot or period

Post by NotNull »

Interesting!

There is a difference between the filesystem, the shell and the filemanager (and programs like Everything)
Support for non-DOS naming isn't available everywhere.

I do this to handle files like that (other than giving them a 'normal' name):

Code: Select all

copy "\\?\C:\temp\period." "\\?\C:\test\period."
(that is using the win32 namespace)

EDIT:That is basically what was in the link you posted. Maybe I should have read that first .... :)


Will test if I can make Everything handle those filenames, but I doubt it ..
NotNull
Posts: 5517
Joined: Wed May 24, 2017 9:22 pm

Re: How Should Everything Handle file with a final dot or period

Post by NotNull »

NotNull wrote:Will test if I can make Everything handle those filenames, but I doubt it ..
Nope, didn't succeed ... but didnt try very long as there is a workaround: a script (as I solve almost everything with a script ;)


EDIT: CMD has only very limited support for these files. The rename command doesn't at all; move halfway, so only thing left wac a copy + delete action.
Better alternatives:
- Powershell : supports most case (script on demand)
- Cygwin's mv (move) command. Makes sense, as it is not based on a Windows API (MSVCRT.dll), but on POSIX. And that's almost native to the filesystem where these files came from (I think)

  • In Everything, search for:
    endwith:.
  • export that list as a text file to an empty folder. Name it period.txt
  • Put CMD script in the same folder
  • Run script


At the end all "filename." files should be renamed to "filename.___"

HTH ...

Code: Select all

@echo off
setlocal
pushd "%~dp0"

	for /f "delims=" %%x in (period.txt) do call :AXI "%%x"

goto :eof

::============================================
:AXI
::============================================
	set THISFILE=%~1
	copy "\\?\%THISFILE%" "\\?\%THISFILE%___"
	if exist "\\?\%THISFILE%___" del "\\?\%THISFILE%"
goto :EOF
void
Developer
Posts: 17157
Joined: Fri Oct 16, 2009 11:31 pm

Re: How Should Everything Handle file with a final dot or period

Post by void »

I've added the \\?\ prefix to filenames ending with . or space for the next version of Everything.

This will allow you to rename from files ending with a . or space in Everything. It will also allow you rename to files ending with a . or space in Everything (which is not supported by the OS).

From the MSDN:

Naming Conventions

The following rules enable applications to create and process valid names for files and directories regardless of the file system:
  • Use a period (.) to separate the base file name from the extension in a directory name or file name.
  • Backslashes (\) are used to separate components in paths, which divides the file name from the path to it, or one directory from one another in a path. You cannot use backslashes in file or directory names. However, they can be required as part of volume names, for example, "C:\". UNC names must adhere to the following format: \\<server>\<share>.
  • Use any character in the current code page for a name, except characters in the range of 0 through 31, or any character that the file system does not allow. A name can contain characters in the extended character set (128–255). However, it cannot contain the following reserved characters:
    < > : " / \ |
  • The following reserved device names cannot be used as the name of a file: CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9. Also avoid these names followed by an extension, for example, NUL.tx7.
    • Windows NT: CLOCK$ is also a reserved device name.
  • Do not assume case sensitivity. Consider names such as OSCAR, Oscar, and oscar to be the same.
  • Do not end a file or directory name with a trailing space or a period. Although the underlying file system may support such names, the operating system does not.
  • Use a period (.) as a directory component in a path to represent the current directory.
  • Use two consecutive periods (..) as a directory component in a path to represent the parent of the current directory.
Some other notes:
As expected, renaming a file or folder to . or .. does not work: Error ERROR_INVALID_NAME (123): The filename, directory name, or volume label syntax is incorrect.
NotNull
Posts: 5517
Joined: Wed May 24, 2017 9:22 pm

Re: How Should Everything Handle file with a final dot or period

Post by NotNull »

void wrote:I've added the \\?\ prefix to filenames ending with . or space for the next version of Everything.
Including support for very long paths?
void
Developer
Posts: 17157
Joined: Fri Oct 16, 2009 11:31 pm

Re: How Should Everything Handle file with a final dot or period

Post by void »

Everything 1.4 should already support very long filenames.

If Everything detects a filename with a length greater than or equal to 260 characters, it will prefix the filename with \\?\

The very long filename limitation still somewhat exists for the shell functions, such as drag drop, copying files to the clipboard and deleting files to the recycle bin.
Windows 10 does have an option to enable very long filenames for the shell:
https://www.howtogeek.com/266621/how-to ... haracters/

Renaming and permanently deleting files in Everything with very long filenames should work.
NotNull
Posts: 5517
Joined: Wed May 24, 2017 9:22 pm

Re: How Should Everything Handle file with a final dot or period

Post by NotNull »

Nice! Thx.
therube
Posts: 5058
Joined: Thu Sep 03, 2009 6:48 pm

Re: How Should Everything rename Handle file with a final dot or period

Post by therube »

I've added the \\?\ prefix to filenames ending with . or space for the next version of Everything.
To be clear, when you spoke at the time, you were speaking of Everything 1.5?


(And the reason it came up, Illegal Characters Are Trying To Cross Our Borders, Help!.)
(Oops, wrong forum, I wanted the Political Discussions Forum & the trump saves the world thread ;-).)
(Don't get me started on other illegal characters, but I'm sure their time will come, dag-na-mit |/<>".)
NotNull
Posts: 5517
Joined: Wed May 24, 2017 9:22 pm

Re: How Should Everything Handle file with a final dot or period

Post by NotNull »

Focusing on filenames with leading and trailing spaces:

Just tested: Everything 1.4.976 does not support this yet.
That is to say: you can run the simulation to trim the spaces (*), but the Windows API's that are used to do the actual renaming don't support it.

Alternative 1: Let Windows take care of it
Using File Explorer, move the file with spaces to a different folder (preferably on the same volume for performance reasons). Windows/ File Explorer doesn't like the extra spaces and will strip them. Now move the file back.
Tested with Win10; don't know about older versions.


Alternative 2: Use PowerShell
When testing this, I discovered a bug in PowerShell (5.1). Luckily I also found a workaround, but it makes the code a little more complicated.
  • In Everything, search for:

    Code: Select all

      endwith:" " | startwith:" "
  • Export the results as a text file. I named mine spaces.txt and it looks like this:
    2020-04-26 01_48_51-C__temp__weg_spaces.txt - Notepad++.png
    2020-04-26 01_48_51-C__temp__weg_spaces.txt - Notepad++.png (15.28 KiB) Viewed 12494 times
  • Start PowerShell and go the folder where you saved your "spaces.txt"
  • Run this command to run a simulation:

    Code: Select all

     gc .\spaces.txt | % {gi "\\?\$_*"} | % {$NewName = $_.DirectoryName + "\" + $_.Name.trim(); rename-item $_* -newname  "$NewName" -whatif}
    
  • If output looks OK, remove the "-whatif" and execute the command again. This will do the actual renaming


My output looks like this:
2020-04-26 01_53_56-Windows PowerShell.png
2020-04-26 01_53_56-Windows PowerShell.png (40.48 KiB) Viewed 12494 times
Important note:
This will probably ONLY work on local NTFS filesystems and not on UNC paths (\\server\share) and non-NTFS filesystems (FATnn, etc).
But I didn't test this.


(*)
In Everything, search for:
endwith:" "|startwith:" "
and feed the results to the rename-tool.
Old format:
^ *(.*?) *$
, New format:
\1
(with regex enabled)
void
Developer
Posts: 17157
Joined: Fri Oct 16, 2009 11:31 pm

Re: How Should Everything Handle file with a final dot or period

Post by void »

To be clear, when you spoke at the time, you were speaking of Everything 1.5?
Yes, sorry.
Everything 1.5 will support the trailing . by prefixing the filename with \\?\
RegexNinja
Posts: 18
Joined: Sat Apr 11, 2020 2:45 pm

Re: How Should Everything Handle file with a final dot or period

Post by RegexNinja »

Hi, here's a way to rename them.. Got the \\?\ prefix-method from therube on another forum (thanx).
Recursively remove 1-trailing dot from filenames.. Run it as-is to preview your NewNames:

ForFiles /s /m *. /c "cmd /c if @isdir==FALSE echo ren \\?\@path @fname" 2>nul
It creates rename commands that would:
ren \\?\"C:\DirPath\FileName1." ------------------> "FileName1"
ren \\?\"C:\DirPath\Deep\FileName2." -----------> "FileName2"
ren \\?\"C:\DirPath\Deep\Deeper\FileName3." --> "FileName3"

Then, just remove echo & run it again... Its an ugly hack, but it works.
Cheers.
Post Reply