How to zip multiple files or folders with WinSCP and automatically keep the file name part?












2














I am using WinSCP and it has the option to use custom commands remotely.



I want to zip some files and folders. WinSCP has a command that can zip a file or folder but I have to enter the name for the zip to be called.



zip -r "!?&Enter an Archive Name:?archive.zip!" !&


I would like a command that will take the name of the file and use that for the zip.



I.e. thisnewvideo.mp4 to become thisnewvideo.zip.



I have a lot of files so typing each title will take a long time.



If it is possible I would like to be able to do multiple files at once and create a separate zip file for each file or folder keeping to original file or folder title.



It needs to be a zip file.










share|improve this question





























    2














    I am using WinSCP and it has the option to use custom commands remotely.



    I want to zip some files and folders. WinSCP has a command that can zip a file or folder but I have to enter the name for the zip to be called.



    zip -r "!?&Enter an Archive Name:?archive.zip!" !&


    I would like a command that will take the name of the file and use that for the zip.



    I.e. thisnewvideo.mp4 to become thisnewvideo.zip.



    I have a lot of files so typing each title will take a long time.



    If it is possible I would like to be able to do multiple files at once and create a separate zip file for each file or folder keeping to original file or folder title.



    It needs to be a zip file.










    share|improve this question



























      2












      2








      2


      1





      I am using WinSCP and it has the option to use custom commands remotely.



      I want to zip some files and folders. WinSCP has a command that can zip a file or folder but I have to enter the name for the zip to be called.



      zip -r "!?&Enter an Archive Name:?archive.zip!" !&


      I would like a command that will take the name of the file and use that for the zip.



      I.e. thisnewvideo.mp4 to become thisnewvideo.zip.



      I have a lot of files so typing each title will take a long time.



      If it is possible I would like to be able to do multiple files at once and create a separate zip file for each file or folder keeping to original file or folder title.



      It needs to be a zip file.










      share|improve this question















      I am using WinSCP and it has the option to use custom commands remotely.



      I want to zip some files and folders. WinSCP has a command that can zip a file or folder but I have to enter the name for the zip to be called.



      zip -r "!?&Enter an Archive Name:?archive.zip!" !&


      I would like a command that will take the name of the file and use that for the zip.



      I.e. thisnewvideo.mp4 to become thisnewvideo.zip.



      I have a lot of files so typing each title will take a long time.



      If it is possible I would like to be able to do multiple files at once and create a separate zip file for each file or folder keeping to original file or folder title.



      It needs to be a zip file.







      winscp






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 6 '15 at 0:28









      Jawa

      3,14982435




      3,14982435










      asked Jan 5 '15 at 23:21









      EzdubEzdub

      1112




      1112






















          2 Answers
          2






          active

          oldest

          votes


















          0














          zip -r `echo ! | sed 's/..*$/.zip/'` !


          It's ok if you want multiple zip



          And monster like that



          ls -q !& > list_1239.txt; zip -9 "!?&FileName:?archive.zip!" $(cat list_1239.txt); rm list_1239.txt


          if you want one big zip-file with custom name






          share|improve this answer































            0














            WinSCP does not have a pattern or any other mechanism to extract filename without extension (or substitute the extension).



            Anyway, you can use any function that the server provides to achieve the same. For example you can replace the extension using the sed command:



            echo thisnewvideo.mp4 | sed 's/..*$/.zip/'


            This will output:



             thisnewvideo.zip


            You can merge this into the WinSCP custom command using backtick operator like:



            zip -r `echo ! | sed 's/..*$/.zip/'` !


            Note that the command is using the ! pattern. When you execute it for a set of selected files, it gets executed once for every file, producing one .zip file for every source file.



            For alternatives see: Extract filename and extension in Bash.



            Note that I would consider better (and easier) to implement it to just append the .zip extension (i.e. thisnewvideo.mp4.zip) to the end of the file name, rather than substituting the extension. You would avoid name clashes, if you have two files with the same base name, just a different extension. But I do not know your constraints.






            share|improve this answer























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "3"
              };
              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%2fsuperuser.com%2fquestions%2f861058%2fhow-to-zip-multiple-files-or-folders-with-winscp-and-automatically-keep-the-file%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              zip -r `echo ! | sed 's/..*$/.zip/'` !


              It's ok if you want multiple zip



              And monster like that



              ls -q !& > list_1239.txt; zip -9 "!?&FileName:?archive.zip!" $(cat list_1239.txt); rm list_1239.txt


              if you want one big zip-file with custom name






              share|improve this answer




























                0














                zip -r `echo ! | sed 's/..*$/.zip/'` !


                It's ok if you want multiple zip



                And monster like that



                ls -q !& > list_1239.txt; zip -9 "!?&FileName:?archive.zip!" $(cat list_1239.txt); rm list_1239.txt


                if you want one big zip-file with custom name






                share|improve this answer


























                  0












                  0








                  0






                  zip -r `echo ! | sed 's/..*$/.zip/'` !


                  It's ok if you want multiple zip



                  And monster like that



                  ls -q !& > list_1239.txt; zip -9 "!?&FileName:?archive.zip!" $(cat list_1239.txt); rm list_1239.txt


                  if you want one big zip-file with custom name






                  share|improve this answer














                  zip -r `echo ! | sed 's/..*$/.zip/'` !


                  It's ok if you want multiple zip



                  And monster like that



                  ls -q !& > list_1239.txt; zip -9 "!?&FileName:?archive.zip!" $(cat list_1239.txt); rm list_1239.txt


                  if you want one big zip-file with custom name







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jul 3 '15 at 13:41

























                  answered Jul 3 '15 at 12:55









                  byKosbyKos

                  11




                  11

























                      0














                      WinSCP does not have a pattern or any other mechanism to extract filename without extension (or substitute the extension).



                      Anyway, you can use any function that the server provides to achieve the same. For example you can replace the extension using the sed command:



                      echo thisnewvideo.mp4 | sed 's/..*$/.zip/'


                      This will output:



                       thisnewvideo.zip


                      You can merge this into the WinSCP custom command using backtick operator like:



                      zip -r `echo ! | sed 's/..*$/.zip/'` !


                      Note that the command is using the ! pattern. When you execute it for a set of selected files, it gets executed once for every file, producing one .zip file for every source file.



                      For alternatives see: Extract filename and extension in Bash.



                      Note that I would consider better (and easier) to implement it to just append the .zip extension (i.e. thisnewvideo.mp4.zip) to the end of the file name, rather than substituting the extension. You would avoid name clashes, if you have two files with the same base name, just a different extension. But I do not know your constraints.






                      share|improve this answer




























                        0














                        WinSCP does not have a pattern or any other mechanism to extract filename without extension (or substitute the extension).



                        Anyway, you can use any function that the server provides to achieve the same. For example you can replace the extension using the sed command:



                        echo thisnewvideo.mp4 | sed 's/..*$/.zip/'


                        This will output:



                         thisnewvideo.zip


                        You can merge this into the WinSCP custom command using backtick operator like:



                        zip -r `echo ! | sed 's/..*$/.zip/'` !


                        Note that the command is using the ! pattern. When you execute it for a set of selected files, it gets executed once for every file, producing one .zip file for every source file.



                        For alternatives see: Extract filename and extension in Bash.



                        Note that I would consider better (and easier) to implement it to just append the .zip extension (i.e. thisnewvideo.mp4.zip) to the end of the file name, rather than substituting the extension. You would avoid name clashes, if you have two files with the same base name, just a different extension. But I do not know your constraints.






                        share|improve this answer


























                          0












                          0








                          0






                          WinSCP does not have a pattern or any other mechanism to extract filename without extension (or substitute the extension).



                          Anyway, you can use any function that the server provides to achieve the same. For example you can replace the extension using the sed command:



                          echo thisnewvideo.mp4 | sed 's/..*$/.zip/'


                          This will output:



                           thisnewvideo.zip


                          You can merge this into the WinSCP custom command using backtick operator like:



                          zip -r `echo ! | sed 's/..*$/.zip/'` !


                          Note that the command is using the ! pattern. When you execute it for a set of selected files, it gets executed once for every file, producing one .zip file for every source file.



                          For alternatives see: Extract filename and extension in Bash.



                          Note that I would consider better (and easier) to implement it to just append the .zip extension (i.e. thisnewvideo.mp4.zip) to the end of the file name, rather than substituting the extension. You would avoid name clashes, if you have two files with the same base name, just a different extension. But I do not know your constraints.






                          share|improve this answer














                          WinSCP does not have a pattern or any other mechanism to extract filename without extension (or substitute the extension).



                          Anyway, you can use any function that the server provides to achieve the same. For example you can replace the extension using the sed command:



                          echo thisnewvideo.mp4 | sed 's/..*$/.zip/'


                          This will output:



                           thisnewvideo.zip


                          You can merge this into the WinSCP custom command using backtick operator like:



                          zip -r `echo ! | sed 's/..*$/.zip/'` !


                          Note that the command is using the ! pattern. When you execute it for a set of selected files, it gets executed once for every file, producing one .zip file for every source file.



                          For alternatives see: Extract filename and extension in Bash.



                          Note that I would consider better (and easier) to implement it to just append the .zip extension (i.e. thisnewvideo.mp4.zip) to the end of the file name, rather than substituting the extension. You would avoid name clashes, if you have two files with the same base name, just a different extension. But I do not know your constraints.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited May 23 '17 at 12:41









                          Community

                          1




                          1










                          answered Jan 6 '15 at 7:50









                          Martin PrikrylMartin Prikryl

                          10.9k43276




                          10.9k43276






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Super User!


                              • 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.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • 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%2fsuperuser.com%2fquestions%2f861058%2fhow-to-zip-multiple-files-or-folders-with-winscp-and-automatically-keep-the-file%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

                              "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                              Alcedinidae

                              Origin of the phrase “under your belt”?