Copy folder names with periods in between words

Discussion in 'Scripting' started by The_Guardian, Apr 17, 2015.

  1. The_Guardian

    The_Guardian Contributor

    May 7, 2012
    2,000
    6,683
    90
    #1 The_Guardian, Apr 17, 2015
    Last edited: Apr 17, 2015
    I was wondering if anyone knows how to copy multiple folders that include periods between words in a cmd file. Problem is there is not set pattern to the folder names. For example...

    1234.1234.12234
    1234.1234
    1234.1234.1234.1234

    I was just going to do a simple
    echo nnn|xcopy /-y "%SystemDrive%\TEST\*" "%SystemDrive%\TEST2"

    This doesn't work because of the wildcard * being present. It cant see the multiple periods in a folder name correct thus it tells me it doesn't exist or nothing copied. I tried the for loop process but that too fails because of * wildcard. I don't know how to make it look for multiple periods in folder names so I can copy over the one that do not exist thus the echo n's to say no to overwriting. I only want what folders are not present in TEST2 folder. Any help would be nice because I am stuck. lol

    So TEST folder has
    1234.1234.12234
    1234.1234
    1234.1234.1234.1234

    TEST2 folder has
    1234.1234.12234
    1234.1234.1234.1234

    I want my script to only copy over folder 1234.1234 since it isn't present in TEST2 folder. I hope everyone can understand.

    Folder names with multiple periods are a pita. lol
     
  2. Kamrul08

    Kamrul08 MDL Member

    Dec 28, 2013
    101
    12
    10
    What is the result with echo nnn|xcopy /e /-y "%SystemDrive%\TEST" "%SystemDrive%\TEST2\"
     
  3. The_Guardian

    The_Guardian Contributor

    May 7, 2012
    2,000
    6,683
    90
    #3 The_Guardian, Apr 17, 2015
    Last edited: Apr 17, 2015
    (OP)
    Holy cow! That worked so I needed the /E then? Thanks for that! :)

    This lead to another issue as I see....how can I add more n's to the echo because it now asks for overwrite on every copied file within the folder? I need more then 3 n's for the script not to stop and ask me for input. Any suggestions on that? lol

    I have tried this method but still cant repeat needed n to echo multiple times...
    for %%a in (C:\TEST\) do if not exist C:\TEST2\%%a echo n|xcopy /e /-y "%SystemDrive%\TEST" "%SystemDrive%\TEST2"
     
  4. nodnar

    nodnar MDL Addicted

    Oct 15, 2011
    925
    587
    30
    nice riddle, guardian!
    have not played with such things in ~10 years..
    but i am tempted to try a double pipe like echo n||-y xcopy etc..
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. The_Guardian

    The_Guardian Contributor

    May 7, 2012
    2,000
    6,683
    90
    #5 The_Guardian, Apr 17, 2015
    Last edited: Apr 17, 2015
    (OP)
    The double pipe fails also...this one here has me stumped. :confused:
    I hate when periods are used in folder names. :mad:

    I don't think it is possible to correct query folder names with multiple periods in them. There is nothing online about how to address something like this. Guess I cant do what I want to do with it. :(
     
  6. The_Guardian

    The_Guardian Contributor

    May 7, 2012
    2,000
    6,683
    90
    #6 The_Guardian, Apr 17, 2015
    Last edited: Apr 17, 2015
    (OP)
    I have gotten a little further but the if not exist isn't working correctly yet...

    for /f "delims=" %%a in ('dir "C:\TEST\" /b /s /a-d ') do (
    for /f "tokens=1,2,3,4 delims=." %%b in ("%%~nxa") do if not exist "C:\TEST2\%%b\" echo n|xcopy /e /-y "C:\TEST\%%b" "C:\TEST2\%%b.%%c%%~xa"
    )

    So TEST folder has
    1234.1234.12234
    1234.1234
    1234.1234.1234.1234

    TEST2 folder has
    1234.1234.12234
    1234.1234.1234.1234

    I only want the 1234.1234 to be copied over to TEST2 directory.

    Ok, got it to do the multiple n's needed for pipe but still tries to copy all folders and files except the one folder I need copied over. hmmmm

    It seems no one online knows how to do this with a cmd file. :(
     
  7. The_Guardian

    The_Guardian Contributor

    May 7, 2012
    2,000
    6,683
    90
    #7 The_Guardian, Apr 17, 2015
    Last edited: Apr 17, 2015
    (OP)
    Got it almost working except for the in not exist but at least it will only list directories now and no pipe error.

    for /f "delims=" %%a in ('dir "C:\TEST\"') do if not exist "C:\TEST2\%%a" xcopy /-y "C:\TEST\%%a" "C:\TEST2\%%a" >C:\NO.txt
     
  8. nodnar

    nodnar MDL Addicted

    Oct 15, 2011
    925
    587
    30
    neither do i, alas..
    all i can think of is first changing all the attributes in TEST to hidden, except for the
    1234.124 thingy, which does not exist in TEST2 of course. and then try again..
    but how to do it while avoiding a response, is another matter..:g:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. The_Guardian

    The_Guardian Contributor

    May 7, 2012
    2,000
    6,683
    90
    #9 The_Guardian, Apr 17, 2015
    Last edited: Apr 17, 2015
    (OP)
    for /f "delims=" %%a in ('dir "C:\TEST\"') do if not exist "C:\TEST2\%%a\" xcopy /-y "C:\TEST\%%a" "C:\TEST2\%%a" >C:\YES.txt

    This almost works but had to echo using a NO.txt file because of pipe error. It just wont copy at all now with the above line but I am closer. lol
    I get file does not exist which it doesn't in TEST2 but it doesn't copy it over...even tried take ownership but that didn't work either. hmmmm
    It only lists the directories now which is correct but the copy over process is failing for some odd reason.

    Also tried with no luck...
    for /f "delims=" %%a in ('dir "C:\TEST\"') do if not exist "C:\TEST2\%%a\" ( xcopy /-y "C:\TEST\%%a" "C:\TEST2\%%a" >C:\YES.txt ) else ( xcopy /-y "C:\TEST\%%a" "C:\TEST2\%%a" >C:\NO.txt )
     
  10. The_Guardian

    The_Guardian Contributor

    May 7, 2012
    2,000
    6,683
    90
    This seems to be real close to working but it says it cant find file so 0 is copied over. :(

    for /D %%a in (C:\TEST\*) do if not exist "C:\TEST2\%%a" echo n| XCOPY /-Y "C:\TEST\%%a" "C:\TEST2\%%a"

    Any suggestions? :confused:
     
  11. The_Guardian

    The_Guardian Contributor

    May 7, 2012
    2,000
    6,683
    90
    #11 The_Guardian, Apr 18, 2015
    Last edited: Apr 18, 2015
    (OP)
    The answer...

    I created a txt file filled with n's to handle pipe errors and all is good. :)

    for /d %%a in ("C:\TEST") do if not exist "C:\TEST2\%%a" ( 2>nul XCOPY "%%a" "C:\TEST2" /E /-Y <"C:\NO.txt" >nul ) >nul

    Copies over folders with multiple periods in the folder name but does not overwrite already present folders in the destination folder. Also null's out all echo's. ;)

    This thread is now closed. Thanks for everyone's input. :hug2:
     
  12. Compo

    Compo MDL Member

    Mar 29, 2011
    137
    103
    10
    #12 Compo, Apr 18, 2015
    Last edited by a moderator: Apr 20, 2017
    Whilst you may be happy with your answer, did you consider using RoboCopy?
    Code:
    ROBOCOPY "%SYSTEMDRIVE%\TEST" "%SYSTEMDRIVE%\TEST2" /E /XC /XN /XO