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
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"
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..
The double pipe fails also...this one here has me stumped. I hate when periods are used in folder names. 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.
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.
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
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..
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 )
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?
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.
Whilst you may be happy with your answer, did you consider using RoboCopy? Code: ROBOCOPY "%SYSTEMDRIVE%\TEST" "%SYSTEMDRIVE%\TEST2" /E /XC /XN /XO