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.
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 »

Latest post of the previous page:

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!
Shmuel
Posts: 6834
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 41 times
Been thanked: 530 times

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

Post by Shmuel »

RegexNinja wrote: Sun 03 May, 2020 21:24 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..
If you meant plugin LuaFAR Search then I can tell it ships with no mask presets.
The plugin shares masks history with Far Manager and any other plugin that uses the database key "Masks".
User avatar
HaRT
Moderator
Posts: 10854
Joined: Tue 30 Aug, 2005 17:21
Has thanked: 221 times
Been thanked: 358 times

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

Post by HaRT »

RegexNinja wrote: Sun 03 May, 2020 21:24 which API FarManager uses to rename
Please refer to the source code (the “Code” link at the very top of the forum page).
RegexNinja wrote: Sun 03 May, 2020 21:24 Does FarManager support macros?
Please read the Help (e.g. by F1), search the Forum (especially FAQ), use Google/Yandex/Bing Translate as needed.
RegexNinja wrote: Sun 03 May, 2020 21:24 I wanted to check the syntax, but havent found a manual that I can read.. I dont do Russian.
You should definitely read more Help before asking questions.
Фар есть инструмент, а не нянька. © 2009 DrKnS
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 21:24Would you happen to know the names of the API(s) which allow this, or have a link to them??
Use any Unicode file function (e.g. CreateFileW) and prefix the filenames with \\?\. That gives you full 32768-character filenames with very few restrictions on their contents.
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!
MoveFileEx, MoveFile.
Now that I've got the app, I did try F7, but it only creates one-directory per F7.
Separate the directory names with a semicolon and check "Process multiple names"
Does FarManager support macros?
There's more functionality in FAR macros than in FAR itself, probably.
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
Thank you very much for all this data. You're a wealth of information!
I'll point them to the github source & reference your data.. I'm no programmer.
I'm sure they'll figure it all out.

Thanks for the semicolon-tip with F7, and I'll definitely be researching the macro-syntax.
Thanks again.. Cheers!
SuperStainless
Posts: 10
Joined: Sat 07 Mar, 2020 16:42
Been thanked: 1 time

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

Post by SuperStainless »

I am new here and probably is not nice to speak about another software, but it is free for personal use. I have been using this program for many years (the consolle version only) integrating it in my Commander menu and it is really powerfull. I rename thousands of files with only one command and recursively.
The software is "Bulk Rename Command Line, by Jim Willsher". The command to remove trailing spaces is like:
brc32.exe /EXECUTE /RECURSIVE /INCLR /REPLACECI:" .":"."
and I run it on current panel from user menu or using complex batch files.

If this message is not polite for this forum, please remove it and excuse me.
Last edited by SuperStainless on Wed 06 May, 2020 00:01, edited 1 time in total.
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 »

SuperStainless
Thanks for the input! Unfortunately, we're trying to handle the illegal-situations that BRC cant touch.
BRC doesnt use the \\?\ prefix that pepak is talking about, so it just cant touch them (uggh).
By 'illegals', I just mean names like "file.txt " instead of file .txt and stuff like 'BadFolderNames ''

I tried using that app too.. Btw that command only removes 1-trailing space before the extension.
If you'd like something to remove any combination of all lead/trailing spaces and/or dots:
brc32 /Recursive /InclR /Regexp:"^[ \.]*(.+?)[ \. ]*$:\1" /Execute

But it still cant touch the illegals, unless they wanna recode the app.
But with FarManagers' LuaFARSearch plug-in, you can do stuff like:
Mask:
/^[ \.]|[ \.]$|[ \.]+\.[^ \.]{1,5}$/
SearchFor:
^[ \.]*|[ \.]+$|[ \.]*(\.[^ \.]{1,5})$
Replace:
$1

That does the same thing as BRC, but also removes the 'illegals' from both files and folders as well..
I dunno what the rules are on Windows filename-extensions, so it just grabs anything from 1-5chars.

Again, thanks for posting. I'm always looking for alternate ways of gettin this kinda stuff done.
I cant speak for the forum, brand new here.. Only a couple-days into the app.
Hopefully, that LuaFAR part will be enough to keep the ban-hammer away, lol.
Cheers!
Last edited by RegexNinja on Wed 06 May, 2020 16:10, edited 1 time in total.
User avatar
HaRT
Moderator
Posts: 10854
Joined: Tue 30 Aug, 2005 17:21
Has thanked: 221 times
Been thanked: 358 times

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

Post by HaRT »

 ! Message from: HaRT
RegexNinja, to make the command lines and regexps less unreadable, you should be using the [c] tag. You should be able to edit your posts now.
Фар есть инструмент, а не нянька. © 2009 DrKnS
Post Reply

Return to “Support and Troubleshooting”