Bulk Correct Files/Folders with incorrect names (e.g. with trailing spaces)

You have encountered a problem using Far Manager? Here you can get help.
CliffyBoy
Posts: 14
Joined: Fri 01 May, 2020 14:29
Been thanked: 1 time

Bulk Correct Files/Folders with trailing spaces

Post by CliffyBoy »

Latest post of the previous page:

Shmuel,

My install path is C:\Users\A1\AppData\Local\Far Manager x64\Plugins, and my folder is named LuafarSearch. I got the plugin from https://github.com/shmuz/far_plugins/re ... lygon-v0.1, and used the source code zip. I dont see anything indicating whether this is x64 or x86. Is this the correct location to get the plugin from? How would I check the bitness factor?
Shmuel
Posts: 6819
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 41 times
Been thanked: 528 times

Bulk Correct Files/Folders with trailing spaces

Post by Shmuel »

CliffyBoy, please go to this page.
Download either x86 or x64 version - it must match your Far Manager bitness.

P.S. Do not jump from this page to Github, this page contains 3 "Download" buttons, here are direct download links:
x86: https://plugring.farmanager.com/download.php?fid=3279
x64: https://plugring.farmanager.com/download.php?fid=3280
Last edited by Shmuel on Sat 02 May, 2020 20:06, edited 2 times in total.
CliffyBoy
Posts: 14
Joined: Fri 01 May, 2020 14:29
Been thanked: 1 time

Bulk Correct Files/Folders with trailing spaces

Post by CliffyBoy »

I fixed the problems. More to follow.
User avatar
HaRT
Moderator
Posts: 10822
Joined: Tue 30 Aug, 2005 17:21
Has thanked: 221 times
Been thanked: 358 times

Bulk Correct Files/Folders with trailing spaces

Post by HaRT »

 ! Message from: HaRT
CliffyBoy wrote: Sat 02 May, 2020 22:24 I fixed the problems.
A polite person would have at least thanked those who helped. I hope they'll learn from what they see.
CliffyBoy wrote: Sat 02 May, 2020 22:24 More to follow.
You should definitely read much more docs and search the forum much more actively before asking further questions.
Фар есть инструмент, а не нянька. © 2009 DrKnS
CliffyBoy
Posts: 14
Joined: Fri 01 May, 2020 14:29
Been thanked: 1 time

Bulk Correct Files/Folders with trailing spaces

Post by CliffyBoy »

Somethings up with this forum page. I dont see new posts when the page is reloaded; Ive refreshed 5 times since 12pm and only now see Shmuel's post when I start a new reply.

Shmuel,
I took a nap to deal with my frustration and when I awoke I realized the issue was likely the bitness. I did a new internet search for LuaFarSearch and I found the page you referenced. I replaced the contents of the github page zip with the plugring.farmanager x64 and bingo now I see the plugin on the popup. I ran it and successfully replaced the illegal character spaces.

Thank you for following up each time with more detail to get this solved. Will the regex also find any other illegal characters in files/folders?
CliffyBoy
Posts: 14
Joined: Fri 01 May, 2020 14:29
Been thanked: 1 time

Bulk Correct Files/Folders with trailing spaces

Post by CliffyBoy »

Hart,

More to follow or (MTF) means that you are giving a quick synopsis of the current situation, with more detail to follow shortly. I also wanted to test a few more files to see how this would work on other illegal characters. To end, I would of course thank everyone who provided assistance on this issue. (SMH) Shake my head.
Last edited by CliffyBoy on Sat 02 May, 2020 22:56, edited 1 time in total.
User avatar
HaRT
Moderator
Posts: 10822
Joined: Tue 30 Aug, 2005 17:21
Has thanked: 221 times
Been thanked: 358 times

Bulk Correct Files/Folders with trailing spaces

Post by HaRT »

 ! Message from: HaRT
CliffyBoy wrote: Sat 02 May, 2020 22:52 More to follow or (MTF) means that you are giving a quick synopsis of the current situation, with more detail to follow shortly.
CliffyBoy wrote: Sat 02 May, 2020 22:47 Will the regex also find any other illegal characters in files/folders?
And “You should definitely read much more docs” means RTFM. :rtfm2:
Фар есть инструмент, а не нянька. © 2009 DrKnS
Shmuel
Posts: 6819
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 41 times
Been thanked: 528 times

Bulk Correct Files/Folders with trailing spaces

Post by Shmuel »

CliffyBoy wrote: Sat 02 May, 2020 22:47 Will the regex also find any other illegal characters in files/folders?
The regex will only find what matches it. The regex I wrote in the screenshot only finds trailing spaces.
If you need to find something different you should write another regex (I can do it for you if you tell exactly what you want).
CliffyBoy
Posts: 14
Joined: Fri 01 May, 2020 14:29
Been thanked: 1 time

Bulk Correct Files/Folders with trailing spaces

Post by CliffyBoy »

Certain files from a remote server are transferred via FTP to a Windows system sometimes with illegal characters that Windows cannot deal with. Im looking for a regex that can find any file/folder in a directory (F:/) for example with illegal characters (which may include a trailing space) for the search field, then another regex that can either substitute and/or remove the illegal character and/or trailing space which would go into the replace part of the plugin.

Thanks
RegexNinja
Posts: 5
Joined: Sat 02 May, 2020 23:34
Location: OrionCygnusArm, MilkyWay
Has thanked: 9 times

Renaming files/folders with illegal characters

Post by RegexNinja »

Hi.

Does FarManager rely on Windows API's for file/folder renaming ??
There are very few apps that dont, most notably archiving-apps like WinRar, 7Zip, etc.
Apparently that's because they're designed to move files across varying OS's with varying illegal-chars?

They're some other 'illegal' situations like "FolderNames \" that end with a trailing space.
Any app relying on the API fails to access (rename/move/copy/delete) such "BadFolderNames \".

I've written a batch to recursively fix such "BadFolderNames \", but most ppl seem to distrust batches.
Also, it relies on short-name generation being enabled, & sed.exe must reside somewhere within %path%.

I'm looking for something more user-friendly that runs in a Windows environment to bulk-remove such trailing spaces.
Removing Illegal-chars like <|:*?> would be a bonus, but mostly concerned with "BadFolderNames \" ending with space.
Does anyone know if FarManager is capable of this??

Thanks in advance!
User avatar
HaRT
Moderator
Posts: 10822
Joined: Tue 30 Aug, 2005 17:21
Has thanked: 221 times
Been thanked: 358 times

Bulk Correct Files/Folders with trailing spaces

Post by HaRT »

 ! Message from: HaRT
RegexNinja, please search the forum next time before creating a new topic.
Фар есть инструмент, а не нянька. © 2009 DrKnS
RegexNinja
Posts: 5
Joined: Sat 02 May, 2020 23:34
Location: OrionCygnusArm, MilkyWay
Has thanked: 9 times

Bulk Correct Files/Folders with incorrect names (e.g. with trailing spaces)

Post by RegexNinja »

Thanks HaRT,
This is right where I wanted to be.. CliffyBoy recommended this app from 'another' forum.
I should've just searched for his name, lol.. Havent downloaded the app yet, just seeking general info..
Does it require an install, or is there a portable version?? I'll research it..

CliffyBoy
Any luck?? So long as it can rename them, and it supports macros, seems like it shouldn't be a prob?
I'll do some research, see what I can find out.. If anyone wants to create "BadFolderNames " for testing:
For /L %A IN (1,1,5) DO @MD "\\?\C:\DirPath\BadName%A " quickly creates 5 such folders within Windows.

Cheers!
pepak
Posts: 604
Joined: Sun 13 Jul, 2008 11:18
Has thanked: 17 times
Been thanked: 54 times

Bulk Correct Files/Folders with incorrect names (e.g. with trailing spaces)

Post by pepak »

RegexNinja wrote: Sun 03 May, 2020 00:31Does FarManager rely on Windows API's for file/folder renaming ??
Of course. Avoiding Windows APIs would require a full re-implementation of the underlying filesystems, along with the ability to access the raw data (i.e. you would need administrative privileges or a supporting driver/service with these privileges).
There are very few apps that dont, most notably archiving-apps like WinRar, 7Zip, etc.
Apparently that's because they're designed to move files across varying OS's with varying illegal-chars?
Even these applications use Windows APIs. Note that there are multiple APIs that can do "the same thing", but some of them allow more detailed control over what is happening.
They're some other 'illegal' situations like "FolderNames \" that end with a trailing space.
Any app relying on the API fails to access (rename/move/copy/delete) such "BadFolderNames \".
Incorrect. An app relying on the wrong API might fail to access.
I'm looking for something more user-friendly that runs in a Windows environment to bulk-remove such trailing spaces.
Removing Illegal-chars like <|:*?> would be a bonus, but mostly concerned with "BadFolderNames \" ending with space.
Does anyone know if FarManager is capable of this??
Sure it is. The steps to achieve that have already been posted to this topic.
Last edited by pepak on Sun 03 May, 2020 08:13, edited 1 time in total.
pepak
Posts: 604
Joined: Sun 13 Jul, 2008 11:18
Has thanked: 17 times
Been thanked: 54 times

Bulk Correct Files/Folders with incorrect names (e.g. with trailing spaces)

Post by pepak »

RegexNinja wrote: Sun 03 May, 2020 02:42If anyone wants to create "BadFolderNames " for testing:
Or just press F7 and create such a directory in FAR...
CliffyBoy
Posts: 14
Joined: Fri 01 May, 2020 14:29
Been thanked: 1 time

Bulk Correct Files/Folders with incorrect names (e.g. with trailing spaces)

Post by CliffyBoy »

So, to wrap things up here is a summary of the steps to remove trailing spaces from files/folders:

Plugin Installation For LuaFAR Search:
1. go to https://plugring.farmanager.com/plugin.php?pid=858&l=en

2. Download either x86 or x64 version - it must match your Far Manager bitness
P.S. Do not jump from this page to Github, use one of the "Download" buttons from this page only

3. go to your Far Manager installation location, (example: C:\Users\UserName\AppData\Local\Far Manager x64\Plugins) enter Plugins folder, make a subfolder called "LuafarSearch" and unpack the plugin archive into this folder. Then restart Far Manager. Make sure the plugin's bitness matches FarManager bitness (either x86 or x64).



Search and Replace using LuaFAR Search

1. Be careful with automatic renaming - it is easy to get it wrong.

2. Using LuaFAR Search plugin: press F11, select LuaFar Search, select Rename,

Code: Select all

╔════════════════════════════ LF Rename ═════════════════════════════╗
║ File mask: *                                                      ↓║
║ (•) Search in all                 [x] Rename files                 ║
║ ( ) Search in selected            [x] Rename folders               ║
║ [x] Process subfolders                                             ║
╟────────────────────────────────────────────────────────────────────╢
║ Search for:                                                        ║
║ \s+$                                                              ↓║
║ Replace with:                                                      ║
║                                                                   ↓║
║   [ ] Function mode               [x] Confirm renaming             ║
║   [x] Log file                                                     ║


Alternate Methods:

1. There are several plugins for files/directory renaming. You can find them by searching on this https://forum.farmanager.com/ and https://plugring.farmanager.com/.

2. Press AltF7
Search for: /.+\s$/
After the search is complete, press [ Panel ] button to move all results to a temporary panel to "delete/correct" or do whatever you need

3. Alternate plugin to try: Visual Rename. It can rename files by RegExp too https://plugring.farmanager.com/


Thanks to all who positively contributed to this discussion and resolution: Shmuel, Yegor, buniak_a_h, pepak, RegexNinja
RegexNinja
Posts: 5
Joined: Sat 02 May, 2020 23:34
Location: OrionCygnusArm, MilkyWay
Has thanked: 9 times

Bulk Correct Files/Folders with incorrect names (e.g. with trailing spaces)

Post by RegexNinja »

pepak
Thanks for all the info..
I was desperately trying to create some illegal-conditions, not knowing the full API details.
Got so frustrated that I ended up using a hex-editor to directly edit the partition table.
Anywho, bricked my laptop for a couple days, till I got a boot-cd.. Wont be doing that again.

Would you happen to know the names of the API(s) which allow this, or have a link to them??
I knew there were different API's for enumerating (vs renaming/deleting/etc), but not multiple-ones to rename.

My guess is that such API's also accept the NT namespace convention, soas to allow POSIX?
Been looking through links like: https://______/en-us/windows/win32/api/fileapi/
and: https://______/en-us/windows/win32/fileio/file-management-control-codes.
Where ___ = docsDotmicrosoftDotcom

I know its possible to mod some API's behavior by sending them path-prefixes like \\?\
My goal is to determine which API FarManager uses to rename, & maybe the format passed to it.
Any help or advice in determining this would be greatly appreciated!

Now that I've got the app, I did try F7, but it only creates one-directory per F7.
Does FarManager support macros? I'd love to create multiple "BadNames " at varying PathDepths.
It does remember LastDirName, so that makes it quicker.. No big deal, I can always batch it.
Again, thanks for the info!


CliffyBoy
Great news, huh! An open-source solution, I was beginning to think it wasnt impossible.
Sorry I didnt try it out earlier, I was still waiting on an answer about the portability.
I confirmed this solution over at the 'other' forum, so everyone knows that it works 100%!

Soooo much faster than my batch, lol... Have you tested this with Unicodes in FolderName??
That's something that'd likely break the batch.. (havent been able to break it otherwise).
So that's another major improvement, not to mention this is all graphical.

Judging by LuaFar's mask-presets, you can tell the authors had illegal-chars in mind.
To see the presets, just backspace thru the FileMask char-by-char until they appear..
Be wary: The version I downloaded had some bad expressions in there..

One of my presets was: /.*[/|\":?\* ].* / (2nd / needs a preceding \ to make it valid).
Its was obviously not meant to be left in there like that, it had alot of extra spaces in set too..
I wanted to check the syntax, but havent found a manual that I can read.. I dont do Russian.

Wish I could create some true illegals like <|:> etc for testing, but I'm done with hex-editors!
Im just praying we can find out the actual API's name, etc.. Then there is hope.
Glad you found a solution.. Cheers!
Post Reply

Return to “Support and Troubleshooting”