Page 1 of 2

rename file from clipboard

Posted: 26 Jan 2021 15:58
by swan_x
i have one folder with some files.
copy to clipboard - item names
on other folder i have same numbers of files but with other names.
i want rename all this files with previous names files captured on my clipboard.... is possible that??

example:
folder1
namo.adc
gerk.erd
alfo.skr

folder2
habx.edf
altr.edg
kal.sft

i want apply same filename of file on folder1 to all files content on folder2

final result:
folder2
namo.adc
gerk.erd
alfo.skr

Re: rename file from clipboard

Posted: 26 Jan 2021 16:20
by highend

Code: Select all

    $clp      = regexreplace(<clp>, "^(.*\\)?");
    $files    = listpane(, , 1, <crlf>);
    $cntClp   = gettoken(trim($clp, <crlf>, "R"), "count", <crlf>)
    $cntFiles = gettoken($files, "count", <crlf>);
    end ($cntClp != $cntFiles), "Number of file(s) in the current pane is<br>NOT EQUAL<br>to the number of file(s) in the clipboard<br><br>Aborted!";
    rename "l", $clp, , $files;

Re: rename file from clipboard

Posted: 26 Jan 2021 17:50
by swan_x
i have 70 files on folder 1
same 70 files on folder 2
dual pane. copy files name on clipboard
run script but have this error: Number of file(s) in the current pane is NOT EQUAL to the number of file(s) in the clipboard Aborted!"

but i have same number of files on folder 1 and on folder 2...

Re: rename file from clipboard

Posted: 26 Jan 2021 17:55
by kunkel321
This can be done manually without too many steps....
Go to Edit > New > New Files..., then paste your list info the window. (Unless I'm mistaken) each line becomes a new file or folder.

EDIT: I've used this feature in the past, but I've never tried it with 70 lines....
EDIT2: Note the slash for folders

Code: Select all

folder1/
namo.adc
gerk.erd
alfo.skr
Forward or backward slash works. Because Don is awesome like that.

EDIT3: For the heck of it I tried with 200 'dummy' files and folders. Worked fine... (img) I forgot to put extensions on the "textfiles" but I don't suppose that makes a difference.
Image

Re: rename file from clipboard

Posted: 26 Jan 2021 18:02
by swan_x
yes work. but have all new file empty.
my intent (and highend script) is to copy file name from 1 folder to other file on folder 2...

i wait highend reply.

Re: rename file from clipboard

Posted: 26 Jan 2021 18:03
by highend

Code: Select all

    $cntClp   = gettoken(<clp>, "count", <crlf>);
    $cntFiles = gettoken(listpane(, , 1, <crlf>), "count", <crlf>);
    text "Clp: $cntClp, files: $cntFiles";
I bet they are not the same^^

Re: rename file from clipboard

Posted: 26 Jan 2021 18:13
by kunkel321
LOL I was so busy tinkering that I didn't even see your replies...

Note also, I think that you can do something like
folder1/file1
folder1/file2
folder1/file2
And all three 'files' will be put into the same 'folder1.'

To get your clipboard contents parsed like that though, yea I guess you'd need some kind of automation.

Also, I can't comment on Highend's code because I'm pretty sure it's written in Greek. LOL.

Re: rename file from clipboard

Posted: 26 Jan 2021 18:19
by highend
Steve, the thing is, he wants to rename existing files, not create new ones :naughty:

Re: rename file from clipboard

Posted: 26 Jan 2021 18:48
by kunkel321
highend wrote: ↑26 Jan 2021 18:19 Steve, the thing is, he wants to rename existing files, not create new ones :naughty:
Ah yes... Upon rereading the top post I see that you are correct. Oh well... At least I had fun doing the screenshots. :whistle:

Re: rename file from clipboard

Posted: 26 Jan 2021 19:39
by swan_x
highend i have run your script but have only this window
Image

????

Re: rename file from clipboard

Posted: 26 Jan 2021 19:42
by highend
As I said, different number of files, hence the error message...

Re: rename file from clipboard

Posted: 27 Jan 2021 08:49
by swan_x
don't understand.
have 70 files on folder 1 and 70 files on folder 2... no other hide file... what file differences between the 2 folders??

and also: what does that Clp:71 mean in the window?? files is 70 correct, but Clp?

EDIT

Re: rename file from clipboard

Posted: 27 Jan 2021 09:01
by highend
have 70 files on folder 1 and 70 folder on folder 2
Files in the first folder and folders in the second folder?
In your initial post you were only talking about files to rename, not folders...
what does that Clp:71 mean in the window
71 items (whatever that are, files or folders) in the clipboard

Re: rename file from clipboard

Posted: 27 Jan 2021 09:14
by swan_x
I was wrong to write. 70 files on folder 1, 70 files on folder 2. now i tried again and the same Clp71 files 70 window always appears to me....

Image

my script used:

Code: Select all

$cntClp   = gettoken(<clp>, "count", <crlf>);
    $cntFiles = gettoken(listpane(, , 1, <crlf>), "count", <crlf>);
    text "Clp: $cntClp, files: $cntFiles";
same window error:

Image

Re: rename file from clipboard

Posted: 27 Jan 2021 09:29
by highend
The reason is:
To clipboard: Item ... contain a trailing <crlf>

The status bar shows the correct amount but the check in the script will fail on this

Fix:

Code: Select all

    $clp      = regexreplace(<clp>, "^(.*\\)?");
    $files    = listpane(, , 1, <crlf>);
    $cntClp   = gettoken(trim($clp, <crlf>, "R"), "count", <crlf>)
    $cntFiles = gettoken($files, "count", <crlf>);
    end ($cntClp != $cntFiles), "Number of file(s) in the current pane is<br>NOT EQUAL<br>to the number of file(s) in the clipboard<br><br>Aborted!";
    rename "l", $clp, , $files;