How to rename files by catalog item to own names?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
MIRKOSOFT
Posts: 70
Joined: 21 Mar 2017 22:44

How to rename files by catalog item to own names?

Postby MIRKOSOFT » 07 Mar 2018 18:42

Hi!

I want to use renaming files to specified length or add/remove extension.
Here's list:
8.3 DOS name
12.3 name
16 character long name
add PRG extension to whole filename with extension
remove extension

I found in keyboard shortcuts script number #112; to rename to DOS 8.3 filenames.
I tried to add it to catalog, but it works not, I added also <curitem> - helped not.
Then I was searching help and found this:

renameitem("John", , , "-01");
or
call renameitem("John", , , "-01");

But how to use it to my wished filename format?

Thank you for each help.
Miro

highend
Posts: 7386
Joined: 06 Feb 2011 00:33

Re: How to rename files by catalog item to own names?

Postby highend » 07 Mar 2018 19:11

I tried to add it to catalog, but it works not, I added also <curitem> - helped not.

#112 copies the short name to the clipboard, why do you think that this changes the name of a file?

Apart from that, by scripting it?

E.g. with the help of these commands:

Code: Select all

getpathcomponent()
strlen()
renameitem() / rename
One of my scripts helped you out? Please donate via Paypal or highend (at) web (dot) de

jupe
Posts: 754
Joined: 20 Oct 2017 21:14

Re: How to rename files by catalog item to own names?

Postby jupe » 08 Mar 2018 00:37

I will give you a couple examples to hopefully help in your endeavor:

This would get a 12.ext with no spaces (if the extension is already more chars, it wouldn't change that)

Code: Select all

renameitem(substr(replace(<curname>, " "), 0, 12), <curitem>);

This would also only work on 1 item at a time, if you want to use it on multiple items it would need modifying.

and to remove extension (again on 1 item at a time) it could be done like this,

Code: Select all

renameitem(<curbase>, , 3);

MIRKOSOFT
Posts: 70
Joined: 21 Mar 2017 22:44

Re: How to rename files by catalog item to own names?

Postby MIRKOSOFT » 12 Mar 2018 19:11

Thank you.

Really I don't know some problems in XYplorer with help and context menu, so I want to ask:
How to add extension to filename?
And how to remove extension and limit filename for 16 characters?
Else one Q is needed - how to limit only 3 or 4 letter extension?

To my problems:
When I open help it hangs whole XYplorer and I must force to close and it means not only help - it closes help and also XYplorer.
Where can be problem?
Context menu: when I right-click on item (file or folder) it changes mouse pointer to waiting circle and after long time it shows mouse pointer back to arrow, but nothing is displayed. So, if I want to get context menu, I must to open folder in Windows Explorer and for this I created button in toolbar which opens current path in Explorer... where can be problem?

Thank you all for all replies and help.
Miro

jupe
Posts: 754
Joined: 20 Oct 2017 21:14

Re: How to rename files by catalog item to own names?

Postby jupe » 13 Mar 2018 08:36

It sounds like you have some dodgy shell extensions in your right click menu, try enabling this setting and see if it helps:

Configuration | General | Menus, Mouse, Safety | Context Menus | Hide shell extensions from shell context menu

Also read this: https://www.xyplorer.com/faq-topic.php?id=ctxcrash

And if it is still not working and you are on 64-bit you could also try toggling this setting

Configuration | Other | Shell Integration | 64-bit Windows | Show the 64-bit context menu

Also your HTML help sounds messed up somehow, as an alternative you could use the PDF version:

https://www.xyplorer.com/download/XYplorerHelp.pdf

or as a long shot look at this: https://www.xyplorer.com/faq-topic.php?id=chm

regarding all the things you want to do, with file extensions etc, most of the answers are contained within the replies already given, then look the functions up in the PDF for more information.

MIRKOSOFT wrote:And how to remove extension and limit filename for 16 characters?

I will give 1 more example that shows how to do what you want on multiple files. You could adapt the previous examples to work on multiple files by modifying this code:

Code: Select all

  foreach ($curitem, <get SelectedItemsNames |>) {
    if (strlen(gpc($curitem, "base") > 16) {
      renameitem(substr(replace(gpc($curitem, "base"), " "), 0, 16), $curitem, 3);
    }
  }

MIRKOSOFT
Posts: 70
Joined: 21 Mar 2017 22:44

Re: How to rename files by catalog item to own names?

Postby MIRKOSOFT » 13 Mar 2018 19:09

Thank you very much!
Context menu works - first I disabled extensions, helped not, I tried all possible, nothing helped, but when I disabled show 64-bit menu, then it works - even I have Windows 10.1709 Pro x64...

I try renaming by your example.

Thank you very very much again!

Miro

MIRKOSOFT
Posts: 70
Joined: 21 Mar 2017 22:44

Re: How to rename files by catalog item to own names?

Postby MIRKOSOFT » 14 Mar 2018 21:06

I finished all wanted operations with files/folders by your example.

Only one thing is problem:

I used for adding PRG extension this:

Code: Select all

  foreach ($curitem, <get SelectedItemsNames |>)
    {
      renameitem("*.?.prg");
    }

problem is that when original filename has not extension is adds PRG extension, but with two dots:
filename
is renamed to
filename..PRG

If filename has extension it works:
filename.ext
is renamed to
filename.ext.PRG

How to fix it?

Thank you for each help.
Miro

highend
Posts: 7386
Joined: 06 Feb 2011 00:33

Re: How to rename files by catalog item to own names?

Postby highend » 14 Mar 2018 21:15

There are multiple ways to do this, one of them:

Code: Select all

    foreach ($curitem, <get SelectedItemsNames |>) {
      renameitem(((gpc($curitem, "ext") != "") ? "*.?.prg" : "*.prg"), $curitem);
    }


Apart from that: Start reading the help file regarding the commands you're using!
Using a foreach loop where your renamitem operation won't work with multiple selected
files is a bit of pointless...
One of my scripts helped you out? Please donate via Paypal or highend (at) web (dot) de

MIRKOSOFT
Posts: 70
Joined: 21 Mar 2017 22:44

Re: How to rename files by catalog item to own names?

Postby MIRKOSOFT » 14 Mar 2018 21:23

Thank you very much!

We can close this thread as solved.

Miro


Return to “Tips & Tricks, Questions & Answers”



Who is online

Users browsing this forum: No registered users and 5 guests