Copy and Rename

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
skehg
Posts: 15
Joined: 20 May 2018 05:33

Copy and Rename

Post by skehg »

Perhaps this should be under Scripts, but is there are a way to copy the selected txt files only and change the extension to csv

You can do this using xcopy in the command prompt but it takes all text files. The xcopy command I use is xcopy *.txt *.csv

jupe
Posts: 2800
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Copy and Rename

Post by jupe »

You are asking in the right place. There are a few ways to do what you asked, here is one:

With your txt files selected:

Code: Select all

 copyas "*.csv";

skehg
Posts: 15
Joined: 20 May 2018 05:33

Re: Copy and Rename

Post by skehg »

OK Great thank you that was easy, how do I now make a right click shortcut menu for that?
Oh and I need it to replace the csv file if it exists already

jupe
Posts: 2800
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Copy and Rename

Post by jupe »

Adding commands to the shell context menu is a little trickier, while possible you would need to do it via registry editing. May I suggest an alternative of the Portable Open with Menu. https://www.xyplorer.com/tour.php?page=pom

Sample entry:

Code: Select all

|"Copy as CSV"txt>::copyas "*.csv";
You have other options like adding it to a toolbar button, catalog item, whitespace context menu too, but the above is the easiest IMO.

edit: I see you just edited your post to say you wanted it to overwrite if file exists now, that is a bit more involved, I haven't got time to write that script myself currently am just going out, I might have later or someone else might in the meantime.

skehg
Posts: 15
Joined: 20 May 2018 05:33

Re: Copy and Rename

Post by skehg »

Thanks Jupe appreciate your help
edit: I notice copyto or moveto has an [on collision] parameter. Should I copyto a programdata temp folder first then do the copyas, then moveto existing folder than clear out the temp folder?

jupe
Posts: 2800
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Copy and Rename

Post by jupe »

You could do it as you describe, there are a number of different possible solutions, here is a rough outline of another way to do it:

Code: Select all

  foreach($curitem, <get selecteditemspathnames |>) {
    writefile(gpc($curitem, "path") . "\" . gpc($curitem, "base") . ".csv", readfile($curitem), "o");
  }
And if you are happy with using previously suggested POM, here is a revised entry (word wrapped):

Code: Select all

|"Copy as CSV"txt>::foreach($curitem, <get selecteditemspathnames |>) { writefile(gpc($curitem, "path") . "\" . gpc($curitem, "base") . ".csv", readfile($curitem), "o"); }	

Post Reply