Merge multiple directories into one, named according to the common directory prefix












0















I made a batch file to rename directories to the string preceding -, but now there is a problem:



Let's say, for example, I had these folders:




Naruto - 480p

Naruto - 720p

Naruto - 1080p




I want to have only one directory, named Naruto, which contains the content of those three directories.



I use this batch file:



for /f "tokens=1*delims=-" %%a in ('dir /b "*-*.*"') do ren "%%a-%%b" "%%a%%~xb"


…but even with the batch file the resultant directories seem to be:




Naruto

Naruto - 720p

Naruto - 1080p




How can I merge the three directories into one which will be named Naruto?










share|improve this question

























  • You cannot rename three directories in one location to the same name, for the same reason you cannot have three files in one directory with the same name and extension! You need to rename, move files and remove directories, or make directory, move files and remove directories.

    – Compo
    Nov 21 '18 at 16:41













  • There is no . character in your directory names either!

    – Compo
    Nov 21 '18 at 17:17











  • You should also use the /AD option so that the DIR command only lists folders.

    – Squashman
    Nov 21 '18 at 17:18
















0















I made a batch file to rename directories to the string preceding -, but now there is a problem:



Let's say, for example, I had these folders:




Naruto - 480p

Naruto - 720p

Naruto - 1080p




I want to have only one directory, named Naruto, which contains the content of those three directories.



I use this batch file:



for /f "tokens=1*delims=-" %%a in ('dir /b "*-*.*"') do ren "%%a-%%b" "%%a%%~xb"


…but even with the batch file the resultant directories seem to be:




Naruto

Naruto - 720p

Naruto - 1080p




How can I merge the three directories into one which will be named Naruto?










share|improve this question

























  • You cannot rename three directories in one location to the same name, for the same reason you cannot have three files in one directory with the same name and extension! You need to rename, move files and remove directories, or make directory, move files and remove directories.

    – Compo
    Nov 21 '18 at 16:41













  • There is no . character in your directory names either!

    – Compo
    Nov 21 '18 at 17:17











  • You should also use the /AD option so that the DIR command only lists folders.

    – Squashman
    Nov 21 '18 at 17:18














0












0








0


0






I made a batch file to rename directories to the string preceding -, but now there is a problem:



Let's say, for example, I had these folders:




Naruto - 480p

Naruto - 720p

Naruto - 1080p




I want to have only one directory, named Naruto, which contains the content of those three directories.



I use this batch file:



for /f "tokens=1*delims=-" %%a in ('dir /b "*-*.*"') do ren "%%a-%%b" "%%a%%~xb"


…but even with the batch file the resultant directories seem to be:




Naruto

Naruto - 720p

Naruto - 1080p




How can I merge the three directories into one which will be named Naruto?










share|improve this question
















I made a batch file to rename directories to the string preceding -, but now there is a problem:



Let's say, for example, I had these folders:




Naruto - 480p

Naruto - 720p

Naruto - 1080p




I want to have only one directory, named Naruto, which contains the content of those three directories.



I use this batch file:



for /f "tokens=1*delims=-" %%a in ('dir /b "*-*.*"') do ren "%%a-%%b" "%%a%%~xb"


…but even with the batch file the resultant directories seem to be:




Naruto

Naruto - 720p

Naruto - 1080p




How can I merge the three directories into one which will be named Naruto?







batch-file for-loop directory






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 18:35









Compo

17k3927




17k3927










asked Nov 21 '18 at 16:18









MELEgrane DellabiMELEgrane Dellabi

14




14













  • You cannot rename three directories in one location to the same name, for the same reason you cannot have three files in one directory with the same name and extension! You need to rename, move files and remove directories, or make directory, move files and remove directories.

    – Compo
    Nov 21 '18 at 16:41













  • There is no . character in your directory names either!

    – Compo
    Nov 21 '18 at 17:17











  • You should also use the /AD option so that the DIR command only lists folders.

    – Squashman
    Nov 21 '18 at 17:18



















  • You cannot rename three directories in one location to the same name, for the same reason you cannot have three files in one directory with the same name and extension! You need to rename, move files and remove directories, or make directory, move files and remove directories.

    – Compo
    Nov 21 '18 at 16:41













  • There is no . character in your directory names either!

    – Compo
    Nov 21 '18 at 17:17











  • You should also use the /AD option so that the DIR command only lists folders.

    – Squashman
    Nov 21 '18 at 17:18

















You cannot rename three directories in one location to the same name, for the same reason you cannot have three files in one directory with the same name and extension! You need to rename, move files and remove directories, or make directory, move files and remove directories.

– Compo
Nov 21 '18 at 16:41







You cannot rename three directories in one location to the same name, for the same reason you cannot have three files in one directory with the same name and extension! You need to rename, move files and remove directories, or make directory, move files and remove directories.

– Compo
Nov 21 '18 at 16:41















There is no . character in your directory names either!

– Compo
Nov 21 '18 at 17:17





There is no . character in your directory names either!

– Compo
Nov 21 '18 at 17:17













You should also use the /AD option so that the DIR command only lists folders.

– Squashman
Nov 21 '18 at 17:18





You should also use the /AD option so that the DIR command only lists folders.

– Squashman
Nov 21 '18 at 17:18












1 Answer
1






active

oldest

votes


















1
















If I understood well, you want to merge these three folders. This is not possible in batchfile language, so you need to move content of the two folders into one, remove them and rename the remaining folder. This is a way you can do it:



@echo off
:: Batch script that merges 3 folders into one!
:: We assume that these 3 folders are located in C: .

for /R C:Naruto-480p %%a IN (*.*) do move "%%a" C:Naruto-1080p
for /R C:Naruto-720p %%b IN (*.*) do move "%%b" C:Naruto-1080p
rd Naruto-480p Naruto-720p
rename Naruto-1080p Naruto


Now let's break out the batch file program:



Lines starting with :: are comments, they are ignored. In fact, they are invalid labels.



for /R C:Naruto-480p %%a IN (*.*) do @move "%%a" C:Naruto-1080p and for /R C:Naruto-720p %%b IN (*.*) do @move "%%b" C:Naruto-1080p. for is a loop as you already know. The /R option tells the loop to run through all the subfolders of the folder specified in the start (C:Naturo-480p and C:Naruto-720p respectively). IN (*.*) means to process ALL files found and, finally, move each file.



rd Naruto-480p Naruto-720p removes folders Naruto-480p and Naruto-720p.



rename Naruto-1080p Naruto renames the folder.



I hope that this helps you exit your trouble :-).






share|improve this answer


























    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%2f53416328%2fmerge-multiple-directories-into-one-named-according-to-the-common-directory-pre%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
















    If I understood well, you want to merge these three folders. This is not possible in batchfile language, so you need to move content of the two folders into one, remove them and rename the remaining folder. This is a way you can do it:



    @echo off
    :: Batch script that merges 3 folders into one!
    :: We assume that these 3 folders are located in C: .

    for /R C:Naruto-480p %%a IN (*.*) do move "%%a" C:Naruto-1080p
    for /R C:Naruto-720p %%b IN (*.*) do move "%%b" C:Naruto-1080p
    rd Naruto-480p Naruto-720p
    rename Naruto-1080p Naruto


    Now let's break out the batch file program:



    Lines starting with :: are comments, they are ignored. In fact, they are invalid labels.



    for /R C:Naruto-480p %%a IN (*.*) do @move "%%a" C:Naruto-1080p and for /R C:Naruto-720p %%b IN (*.*) do @move "%%b" C:Naruto-1080p. for is a loop as you already know. The /R option tells the loop to run through all the subfolders of the folder specified in the start (C:Naturo-480p and C:Naruto-720p respectively). IN (*.*) means to process ALL files found and, finally, move each file.



    rd Naruto-480p Naruto-720p removes folders Naruto-480p and Naruto-720p.



    rename Naruto-1080p Naruto renames the folder.



    I hope that this helps you exit your trouble :-).






    share|improve this answer






























      1
















      If I understood well, you want to merge these three folders. This is not possible in batchfile language, so you need to move content of the two folders into one, remove them and rename the remaining folder. This is a way you can do it:



      @echo off
      :: Batch script that merges 3 folders into one!
      :: We assume that these 3 folders are located in C: .

      for /R C:Naruto-480p %%a IN (*.*) do move "%%a" C:Naruto-1080p
      for /R C:Naruto-720p %%b IN (*.*) do move "%%b" C:Naruto-1080p
      rd Naruto-480p Naruto-720p
      rename Naruto-1080p Naruto


      Now let's break out the batch file program:



      Lines starting with :: are comments, they are ignored. In fact, they are invalid labels.



      for /R C:Naruto-480p %%a IN (*.*) do @move "%%a" C:Naruto-1080p and for /R C:Naruto-720p %%b IN (*.*) do @move "%%b" C:Naruto-1080p. for is a loop as you already know. The /R option tells the loop to run through all the subfolders of the folder specified in the start (C:Naturo-480p and C:Naruto-720p respectively). IN (*.*) means to process ALL files found and, finally, move each file.



      rd Naruto-480p Naruto-720p removes folders Naruto-480p and Naruto-720p.



      rename Naruto-1080p Naruto renames the folder.



      I hope that this helps you exit your trouble :-).






      share|improve this answer




























        1












        1








        1









        If I understood well, you want to merge these three folders. This is not possible in batchfile language, so you need to move content of the two folders into one, remove them and rename the remaining folder. This is a way you can do it:



        @echo off
        :: Batch script that merges 3 folders into one!
        :: We assume that these 3 folders are located in C: .

        for /R C:Naruto-480p %%a IN (*.*) do move "%%a" C:Naruto-1080p
        for /R C:Naruto-720p %%b IN (*.*) do move "%%b" C:Naruto-1080p
        rd Naruto-480p Naruto-720p
        rename Naruto-1080p Naruto


        Now let's break out the batch file program:



        Lines starting with :: are comments, they are ignored. In fact, they are invalid labels.



        for /R C:Naruto-480p %%a IN (*.*) do @move "%%a" C:Naruto-1080p and for /R C:Naruto-720p %%b IN (*.*) do @move "%%b" C:Naruto-1080p. for is a loop as you already know. The /R option tells the loop to run through all the subfolders of the folder specified in the start (C:Naturo-480p and C:Naruto-720p respectively). IN (*.*) means to process ALL files found and, finally, move each file.



        rd Naruto-480p Naruto-720p removes folders Naruto-480p and Naruto-720p.



        rename Naruto-1080p Naruto renames the folder.



        I hope that this helps you exit your trouble :-).






        share|improve this answer

















        If I understood well, you want to merge these three folders. This is not possible in batchfile language, so you need to move content of the two folders into one, remove them and rename the remaining folder. This is a way you can do it:



        @echo off
        :: Batch script that merges 3 folders into one!
        :: We assume that these 3 folders are located in C: .

        for /R C:Naruto-480p %%a IN (*.*) do move "%%a" C:Naruto-1080p
        for /R C:Naruto-720p %%b IN (*.*) do move "%%b" C:Naruto-1080p
        rd Naruto-480p Naruto-720p
        rename Naruto-1080p Naruto


        Now let's break out the batch file program:



        Lines starting with :: are comments, they are ignored. In fact, they are invalid labels.



        for /R C:Naruto-480p %%a IN (*.*) do @move "%%a" C:Naruto-1080p and for /R C:Naruto-720p %%b IN (*.*) do @move "%%b" C:Naruto-1080p. for is a loop as you already know. The /R option tells the loop to run through all the subfolders of the folder specified in the start (C:Naturo-480p and C:Naruto-720p respectively). IN (*.*) means to process ALL files found and, finally, move each file.



        rd Naruto-480p Naruto-720p removes folders Naruto-480p and Naruto-720p.



        rename Naruto-1080p Naruto renames the folder.



        I hope that this helps you exit your trouble :-).







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 25 '18 at 16:34

























        answered Nov 21 '18 at 17:50









        double-beepdouble-beep

        3,08141432




        3,08141432
































            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%2f53416328%2fmerge-multiple-directories-into-one-named-according-to-the-common-directory-pre%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

            鏡平學校

            ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

            Why https connections are so slow when debugging (stepping over) in Java?