Page 1 of 1

Copy and Rename

Posted: 24 May 2018 02:59
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

Re: Copy and Rename

Posted: 24 May 2018 03:13
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";

Re: Copy and Rename

Posted: 24 May 2018 03:23
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

Re: Copy and Rename

Posted: 24 May 2018 03:38
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.

Re: Copy and Rename

Posted: 24 May 2018 04:10
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?

Re: Copy and Rename

Posted: 24 May 2018 06:59
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"); }