How to expand to current remote path in custom command prompt in WinSCP?












1















I tried to make a custom command that unzip a selected file to a path defined by user, but with a default value to current path and current archive name in remote server using this command, but the prompt just gave me an empty value. What's the mistake?



unzip "!" -d "!?&Extraction Path:?!/!!"


Thanks in advance!










share|improve this question





























    1















    I tried to make a custom command that unzip a selected file to a path defined by user, but with a default value to current path and current archive name in remote server using this command, but the prompt just gave me an empty value. What's the mistake?



    unzip "!" -d "!?&Extraction Path:?!/!!"


    Thanks in advance!










    share|improve this question



























      1












      1








      1


      1






      I tried to make a custom command that unzip a selected file to a path defined by user, but with a default value to current path and current archive name in remote server using this command, but the prompt just gave me an empty value. What's the mistake?



      unzip "!" -d "!?&Extraction Path:?!/!!"


      Thanks in advance!










      share|improve this question
















      I tried to make a custom command that unzip a selected file to a path defined by user, but with a default value to current path and current archive name in remote server using this command, but the prompt just gave me an empty value. What's the mistake?



      unzip "!" -d "!?&Extraction Path:?!/!!"


      Thanks in advance!







      winscp






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 7:23









      Martin Prikryl

      86.4k22164360




      86.4k22164360










      asked Nov 12 '18 at 15:39









      Gregor IsackGregor Isack

      456312




      456312
























          1 Answer
          1






          active

          oldest

          votes


















          1














          It's not possible. There's actually a feature request for this functionality:
          Bug 743 – Allow patterns in default prompt answer in custom commands.



          Though even that it meant to support only static (non-file) patterns like !/, but not file patterns like !.





          If it helps, in WinSCP extensions, it's possible to use non-file patterns, like !/ (but not file patterns, like !) in default prompt/option answer.



          The extension file may look like:



          @name     Unzip...
          @side Remote
          @command unzip "!" -d "%ExtractionPath%"
          @option ExtractionPath -run textbox "Extraction path:" "!/"


          Just store the above script to a text file and install it to WinSCP.





          Another thing that you can do, is to add a checkbox that will make WinSCP add an archive name (without an extension) to the path, with some clever use of shell (bash) constructs. This way, you can uncheck the checkbox and add a custom subfolder to the target path manually, if you do not want to use the archive name for the subfolder name.



          @name     Unzip...
          @side Remote
          @command unzip "!" -d "%ExtractionPath%`[[ '%AddName%' = '1' ]] && AN=! && echo ${AN%.*}`"
          @option ExtractionPath -run textbox "Extraction path:" "!/"
          @option AddName -run checkbox "Add file name to the extraction path" "1" "1"


          enter image description here





          Yet another alternative is to use your own placeholder for archive name (e.g. ARCHIVENAME) that will get replaced by real name (without an extension), when the command is executed. Then, if you do not want to use the archive name for the subfolder name, you replace the ARCHIVENAME with a custom name.



          @name     Unzip...
          @side Remote
          @command unzip "!" -d "`EP=%ExtractionPath%;AN=!;AN=${AN%.*};echo ${EP/ARCHIVENAME/$AN}`"
          @option ExtractionPath -run textbox "Extraction path:" "!/ARCHIVENAME"


          enter image description here






          share|improve this answer





















          • 1





            That last method is genius! Thank you for the very thorough answer!

            – Gregor Isack
            Nov 13 '18 at 12:30











          • Hey I try to modify the last command a little bit to make it remove the file extension by using this command @command unzip "!" -d "``EP=%ExtractionPath%;echo $(${EP/ARCHIVENAME/!} | awk -F. '{ print $1 }')``" and WinSCP hanged on executing command and give me an error saying Host is not communicating..., any idea why? PS: dont worry about the extra `` mark, it's the formatting which I don't know how to fix yet.

            – Gregor Isack
            Nov 13 '18 at 13:14













          • Ah okay, let's say I have an archive named archive.zip, using the command in last method would failed since unzip can't extract to the same path that contains the same name of archive, for example, extracting /home/martin/archive.zip to /home/martin/archive.zip (even though it's the folder name) would failed. And yeah you're right that it would modify the custom name, which I'll try to solve it after.

            – Gregor Isack
            Nov 13 '18 at 13:27













          • That works perfectly now! Btw I nerver see one uses ${AN%.*} before (and it looks shorter and more efficient than sed or awk, would you mind explain what the specifier did?

            – Gregor Isack
            Nov 13 '18 at 14:15






          • 1





            I took it from here: stackoverflow.com/q/965053/850848#965072 - Explained here: gnu.org/software/bash/manual/html_node/… (though I cannot really say, I understand it fully).

            – Martin Prikryl
            Nov 13 '18 at 14:17













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265457%2fhow-to-expand-to-current-remote-path-in-custom-command-prompt-in-winscp%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          It's not possible. There's actually a feature request for this functionality:
          Bug 743 – Allow patterns in default prompt answer in custom commands.



          Though even that it meant to support only static (non-file) patterns like !/, but not file patterns like !.





          If it helps, in WinSCP extensions, it's possible to use non-file patterns, like !/ (but not file patterns, like !) in default prompt/option answer.



          The extension file may look like:



          @name     Unzip...
          @side Remote
          @command unzip "!" -d "%ExtractionPath%"
          @option ExtractionPath -run textbox "Extraction path:" "!/"


          Just store the above script to a text file and install it to WinSCP.





          Another thing that you can do, is to add a checkbox that will make WinSCP add an archive name (without an extension) to the path, with some clever use of shell (bash) constructs. This way, you can uncheck the checkbox and add a custom subfolder to the target path manually, if you do not want to use the archive name for the subfolder name.



          @name     Unzip...
          @side Remote
          @command unzip "!" -d "%ExtractionPath%`[[ '%AddName%' = '1' ]] && AN=! && echo ${AN%.*}`"
          @option ExtractionPath -run textbox "Extraction path:" "!/"
          @option AddName -run checkbox "Add file name to the extraction path" "1" "1"


          enter image description here





          Yet another alternative is to use your own placeholder for archive name (e.g. ARCHIVENAME) that will get replaced by real name (without an extension), when the command is executed. Then, if you do not want to use the archive name for the subfolder name, you replace the ARCHIVENAME with a custom name.



          @name     Unzip...
          @side Remote
          @command unzip "!" -d "`EP=%ExtractionPath%;AN=!;AN=${AN%.*};echo ${EP/ARCHIVENAME/$AN}`"
          @option ExtractionPath -run textbox "Extraction path:" "!/ARCHIVENAME"


          enter image description here






          share|improve this answer





















          • 1





            That last method is genius! Thank you for the very thorough answer!

            – Gregor Isack
            Nov 13 '18 at 12:30











          • Hey I try to modify the last command a little bit to make it remove the file extension by using this command @command unzip "!" -d "``EP=%ExtractionPath%;echo $(${EP/ARCHIVENAME/!} | awk -F. '{ print $1 }')``" and WinSCP hanged on executing command and give me an error saying Host is not communicating..., any idea why? PS: dont worry about the extra `` mark, it's the formatting which I don't know how to fix yet.

            – Gregor Isack
            Nov 13 '18 at 13:14













          • Ah okay, let's say I have an archive named archive.zip, using the command in last method would failed since unzip can't extract to the same path that contains the same name of archive, for example, extracting /home/martin/archive.zip to /home/martin/archive.zip (even though it's the folder name) would failed. And yeah you're right that it would modify the custom name, which I'll try to solve it after.

            – Gregor Isack
            Nov 13 '18 at 13:27













          • That works perfectly now! Btw I nerver see one uses ${AN%.*} before (and it looks shorter and more efficient than sed or awk, would you mind explain what the specifier did?

            – Gregor Isack
            Nov 13 '18 at 14:15






          • 1





            I took it from here: stackoverflow.com/q/965053/850848#965072 - Explained here: gnu.org/software/bash/manual/html_node/… (though I cannot really say, I understand it fully).

            – Martin Prikryl
            Nov 13 '18 at 14:17


















          1














          It's not possible. There's actually a feature request for this functionality:
          Bug 743 – Allow patterns in default prompt answer in custom commands.



          Though even that it meant to support only static (non-file) patterns like !/, but not file patterns like !.





          If it helps, in WinSCP extensions, it's possible to use non-file patterns, like !/ (but not file patterns, like !) in default prompt/option answer.



          The extension file may look like:



          @name     Unzip...
          @side Remote
          @command unzip "!" -d "%ExtractionPath%"
          @option ExtractionPath -run textbox "Extraction path:" "!/"


          Just store the above script to a text file and install it to WinSCP.





          Another thing that you can do, is to add a checkbox that will make WinSCP add an archive name (without an extension) to the path, with some clever use of shell (bash) constructs. This way, you can uncheck the checkbox and add a custom subfolder to the target path manually, if you do not want to use the archive name for the subfolder name.



          @name     Unzip...
          @side Remote
          @command unzip "!" -d "%ExtractionPath%`[[ '%AddName%' = '1' ]] && AN=! && echo ${AN%.*}`"
          @option ExtractionPath -run textbox "Extraction path:" "!/"
          @option AddName -run checkbox "Add file name to the extraction path" "1" "1"


          enter image description here





          Yet another alternative is to use your own placeholder for archive name (e.g. ARCHIVENAME) that will get replaced by real name (without an extension), when the command is executed. Then, if you do not want to use the archive name for the subfolder name, you replace the ARCHIVENAME with a custom name.



          @name     Unzip...
          @side Remote
          @command unzip "!" -d "`EP=%ExtractionPath%;AN=!;AN=${AN%.*};echo ${EP/ARCHIVENAME/$AN}`"
          @option ExtractionPath -run textbox "Extraction path:" "!/ARCHIVENAME"


          enter image description here






          share|improve this answer





















          • 1





            That last method is genius! Thank you for the very thorough answer!

            – Gregor Isack
            Nov 13 '18 at 12:30











          • Hey I try to modify the last command a little bit to make it remove the file extension by using this command @command unzip "!" -d "``EP=%ExtractionPath%;echo $(${EP/ARCHIVENAME/!} | awk -F. '{ print $1 }')``" and WinSCP hanged on executing command and give me an error saying Host is not communicating..., any idea why? PS: dont worry about the extra `` mark, it's the formatting which I don't know how to fix yet.

            – Gregor Isack
            Nov 13 '18 at 13:14













          • Ah okay, let's say I have an archive named archive.zip, using the command in last method would failed since unzip can't extract to the same path that contains the same name of archive, for example, extracting /home/martin/archive.zip to /home/martin/archive.zip (even though it's the folder name) would failed. And yeah you're right that it would modify the custom name, which I'll try to solve it after.

            – Gregor Isack
            Nov 13 '18 at 13:27













          • That works perfectly now! Btw I nerver see one uses ${AN%.*} before (and it looks shorter and more efficient than sed or awk, would you mind explain what the specifier did?

            – Gregor Isack
            Nov 13 '18 at 14:15






          • 1





            I took it from here: stackoverflow.com/q/965053/850848#965072 - Explained here: gnu.org/software/bash/manual/html_node/… (though I cannot really say, I understand it fully).

            – Martin Prikryl
            Nov 13 '18 at 14:17
















          1












          1








          1







          It's not possible. There's actually a feature request for this functionality:
          Bug 743 – Allow patterns in default prompt answer in custom commands.



          Though even that it meant to support only static (non-file) patterns like !/, but not file patterns like !.





          If it helps, in WinSCP extensions, it's possible to use non-file patterns, like !/ (but not file patterns, like !) in default prompt/option answer.



          The extension file may look like:



          @name     Unzip...
          @side Remote
          @command unzip "!" -d "%ExtractionPath%"
          @option ExtractionPath -run textbox "Extraction path:" "!/"


          Just store the above script to a text file and install it to WinSCP.





          Another thing that you can do, is to add a checkbox that will make WinSCP add an archive name (without an extension) to the path, with some clever use of shell (bash) constructs. This way, you can uncheck the checkbox and add a custom subfolder to the target path manually, if you do not want to use the archive name for the subfolder name.



          @name     Unzip...
          @side Remote
          @command unzip "!" -d "%ExtractionPath%`[[ '%AddName%' = '1' ]] && AN=! && echo ${AN%.*}`"
          @option ExtractionPath -run textbox "Extraction path:" "!/"
          @option AddName -run checkbox "Add file name to the extraction path" "1" "1"


          enter image description here





          Yet another alternative is to use your own placeholder for archive name (e.g. ARCHIVENAME) that will get replaced by real name (without an extension), when the command is executed. Then, if you do not want to use the archive name for the subfolder name, you replace the ARCHIVENAME with a custom name.



          @name     Unzip...
          @side Remote
          @command unzip "!" -d "`EP=%ExtractionPath%;AN=!;AN=${AN%.*};echo ${EP/ARCHIVENAME/$AN}`"
          @option ExtractionPath -run textbox "Extraction path:" "!/ARCHIVENAME"


          enter image description here






          share|improve this answer















          It's not possible. There's actually a feature request for this functionality:
          Bug 743 – Allow patterns in default prompt answer in custom commands.



          Though even that it meant to support only static (non-file) patterns like !/, but not file patterns like !.





          If it helps, in WinSCP extensions, it's possible to use non-file patterns, like !/ (but not file patterns, like !) in default prompt/option answer.



          The extension file may look like:



          @name     Unzip...
          @side Remote
          @command unzip "!" -d "%ExtractionPath%"
          @option ExtractionPath -run textbox "Extraction path:" "!/"


          Just store the above script to a text file and install it to WinSCP.





          Another thing that you can do, is to add a checkbox that will make WinSCP add an archive name (without an extension) to the path, with some clever use of shell (bash) constructs. This way, you can uncheck the checkbox and add a custom subfolder to the target path manually, if you do not want to use the archive name for the subfolder name.



          @name     Unzip...
          @side Remote
          @command unzip "!" -d "%ExtractionPath%`[[ '%AddName%' = '1' ]] && AN=! && echo ${AN%.*}`"
          @option ExtractionPath -run textbox "Extraction path:" "!/"
          @option AddName -run checkbox "Add file name to the extraction path" "1" "1"


          enter image description here





          Yet another alternative is to use your own placeholder for archive name (e.g. ARCHIVENAME) that will get replaced by real name (without an extension), when the command is executed. Then, if you do not want to use the archive name for the subfolder name, you replace the ARCHIVENAME with a custom name.



          @name     Unzip...
          @side Remote
          @command unzip "!" -d "`EP=%ExtractionPath%;AN=!;AN=${AN%.*};echo ${EP/ARCHIVENAME/$AN}`"
          @option ExtractionPath -run textbox "Extraction path:" "!/ARCHIVENAME"


          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 13 '18 at 13:41

























          answered Nov 12 '18 at 16:31









          Martin PrikrylMartin Prikryl

          86.4k22164360




          86.4k22164360








          • 1





            That last method is genius! Thank you for the very thorough answer!

            – Gregor Isack
            Nov 13 '18 at 12:30











          • Hey I try to modify the last command a little bit to make it remove the file extension by using this command @command unzip "!" -d "``EP=%ExtractionPath%;echo $(${EP/ARCHIVENAME/!} | awk -F. '{ print $1 }')``" and WinSCP hanged on executing command and give me an error saying Host is not communicating..., any idea why? PS: dont worry about the extra `` mark, it's the formatting which I don't know how to fix yet.

            – Gregor Isack
            Nov 13 '18 at 13:14













          • Ah okay, let's say I have an archive named archive.zip, using the command in last method would failed since unzip can't extract to the same path that contains the same name of archive, for example, extracting /home/martin/archive.zip to /home/martin/archive.zip (even though it's the folder name) would failed. And yeah you're right that it would modify the custom name, which I'll try to solve it after.

            – Gregor Isack
            Nov 13 '18 at 13:27













          • That works perfectly now! Btw I nerver see one uses ${AN%.*} before (and it looks shorter and more efficient than sed or awk, would you mind explain what the specifier did?

            – Gregor Isack
            Nov 13 '18 at 14:15






          • 1





            I took it from here: stackoverflow.com/q/965053/850848#965072 - Explained here: gnu.org/software/bash/manual/html_node/… (though I cannot really say, I understand it fully).

            – Martin Prikryl
            Nov 13 '18 at 14:17
















          • 1





            That last method is genius! Thank you for the very thorough answer!

            – Gregor Isack
            Nov 13 '18 at 12:30











          • Hey I try to modify the last command a little bit to make it remove the file extension by using this command @command unzip "!" -d "``EP=%ExtractionPath%;echo $(${EP/ARCHIVENAME/!} | awk -F. '{ print $1 }')``" and WinSCP hanged on executing command and give me an error saying Host is not communicating..., any idea why? PS: dont worry about the extra `` mark, it's the formatting which I don't know how to fix yet.

            – Gregor Isack
            Nov 13 '18 at 13:14













          • Ah okay, let's say I have an archive named archive.zip, using the command in last method would failed since unzip can't extract to the same path that contains the same name of archive, for example, extracting /home/martin/archive.zip to /home/martin/archive.zip (even though it's the folder name) would failed. And yeah you're right that it would modify the custom name, which I'll try to solve it after.

            – Gregor Isack
            Nov 13 '18 at 13:27













          • That works perfectly now! Btw I nerver see one uses ${AN%.*} before (and it looks shorter and more efficient than sed or awk, would you mind explain what the specifier did?

            – Gregor Isack
            Nov 13 '18 at 14:15






          • 1





            I took it from here: stackoverflow.com/q/965053/850848#965072 - Explained here: gnu.org/software/bash/manual/html_node/… (though I cannot really say, I understand it fully).

            – Martin Prikryl
            Nov 13 '18 at 14:17










          1




          1





          That last method is genius! Thank you for the very thorough answer!

          – Gregor Isack
          Nov 13 '18 at 12:30





          That last method is genius! Thank you for the very thorough answer!

          – Gregor Isack
          Nov 13 '18 at 12:30













          Hey I try to modify the last command a little bit to make it remove the file extension by using this command @command unzip "!" -d "``EP=%ExtractionPath%;echo $(${EP/ARCHIVENAME/!} | awk -F. '{ print $1 }')``" and WinSCP hanged on executing command and give me an error saying Host is not communicating..., any idea why? PS: dont worry about the extra `` mark, it's the formatting which I don't know how to fix yet.

          – Gregor Isack
          Nov 13 '18 at 13:14







          Hey I try to modify the last command a little bit to make it remove the file extension by using this command @command unzip "!" -d "``EP=%ExtractionPath%;echo $(${EP/ARCHIVENAME/!} | awk -F. '{ print $1 }')``" and WinSCP hanged on executing command and give me an error saying Host is not communicating..., any idea why? PS: dont worry about the extra `` mark, it's the formatting which I don't know how to fix yet.

          – Gregor Isack
          Nov 13 '18 at 13:14















          Ah okay, let's say I have an archive named archive.zip, using the command in last method would failed since unzip can't extract to the same path that contains the same name of archive, for example, extracting /home/martin/archive.zip to /home/martin/archive.zip (even though it's the folder name) would failed. And yeah you're right that it would modify the custom name, which I'll try to solve it after.

          – Gregor Isack
          Nov 13 '18 at 13:27







          Ah okay, let's say I have an archive named archive.zip, using the command in last method would failed since unzip can't extract to the same path that contains the same name of archive, for example, extracting /home/martin/archive.zip to /home/martin/archive.zip (even though it's the folder name) would failed. And yeah you're right that it would modify the custom name, which I'll try to solve it after.

          – Gregor Isack
          Nov 13 '18 at 13:27















          That works perfectly now! Btw I nerver see one uses ${AN%.*} before (and it looks shorter and more efficient than sed or awk, would you mind explain what the specifier did?

          – Gregor Isack
          Nov 13 '18 at 14:15





          That works perfectly now! Btw I nerver see one uses ${AN%.*} before (and it looks shorter and more efficient than sed or awk, would you mind explain what the specifier did?

          – Gregor Isack
          Nov 13 '18 at 14:15




          1




          1





          I took it from here: stackoverflow.com/q/965053/850848#965072 - Explained here: gnu.org/software/bash/manual/html_node/… (though I cannot really say, I understand it fully).

          – Martin Prikryl
          Nov 13 '18 at 14:17







          I took it from here: stackoverflow.com/q/965053/850848#965072 - Explained here: gnu.org/software/bash/manual/html_node/… (though I cannot really say, I understand it fully).

          – Martin Prikryl
          Nov 13 '18 at 14:17




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265457%2fhow-to-expand-to-current-remote-path-in-custom-command-prompt-in-winscp%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Full-time equivalent

          さくらももこ

          13 indicted, 8 arrested in Calif. drug cartel investigation