Please, if possible I request help, I need 3 batch files in order to do the following tasks: BATCH01 Go to drive X1:\ => Delete everything (folder, subfolders and files) exept folders "X1:\System Volume Information" and "X1:\$RECYCLE.BIN" Go to drive X2:\ => Copy everything (folder, subfolders and files) exept folders "X2:\System Volume Information" and "X2:\$RECYCLE.BIN" => Go to drive X1:\ => Paste everything (folder, subfolders and files) BATCH02 Go to drive X3:\ => Go to folder X3:\Y3 => Delete everything (folder, subfolders and files) Go to drive X4:\ => Go to folder X4:\Y4 => Copy everything (folder, subfolders and files) => Go to folder X3:\Y3 => Paste everything (folder, subfolders and files) BATCH03 Go to drive X5:\ => Delete everything (folder, subfolders and files) exept folders "X5:\System Volume Information", "X5:\$RECYCLE.BIN" and "X5:\Whatever" Go to drive X6:\ => Copy everything (folder, subfolders and files) exept folders "X6:\System Volume Information", "X6:\$RECYCLE.BIN" and "X6:\WhateverAgain" => Go to drive X5:\ => Paste everything (folder, subfolders and files) Thank you in advance
I don't have time to write it all out. You can look at this for the delete portions: https://stackoverflow.com/questions...rectories-except-specified-file-and-directory For the copy parts you could just "xcopy X2 *.* /s X1" (as an example). Or you could wait for a more detailed answer form someone that has to time to write it all out.
Thanks for your help. I understand you're busy. But I never wrote a batch file. I tried to follow the example you kindly shared with me. Please, it'll be great if you can give me a hand, confirming me if this (below) will work for the BATCH01 I requested. Thks! @Echo Off SETLOCAL SET "sourcedir=F:\" SET "keepdir=System Volume Information" SET "keepdir="$RECYCLE.BIN" FOR /d %%a IN ("%sourcedir%\*") DO IF /i NOT "%%~nxa"=="%keepdir%" RD /S /Q "%%a" SETLOCAL SET "sourcedir=E:\" SET "keepdir=System Volume Information" SET "keepdir="$RECYCLE.BIN" FOR /d %%a IN ("%sourcedir%\*") DO IF /i NOT "%%~nxa"=="%keepdir%" XCOPY E:\*.* /s F:\ GOTO :EOF
If you're not in a hurry and someone else doesn't help first I'll see what I can do later. I see you're setting the "keepdir" twice. The second one will probably replace the first one in that example so it will need some tweaking.
Another method for BATCH03 X5 is F:\ X6 is H:\ Two batch files. Run them as Admin. 1.cmd is... Code: @echo off CD /d %~dp0 MD F:\delete robocopy F:\ F:\delete /e /move /create /XD Whatever "System Volume Information" Recycler $Recycle.bin RD F:\delete /s /q 2.cmd is... Code: @echo off CD /d %~dp0 robocopy.exe H:\ F:\ *.* /mir /XD Whatever "System Volume Information" Recycler $Recycle.bin /copy:DAT /dcopy:DA /r:0 /v /xj /mt:32 Good luck. I did some rough testing.
A single batch file will work... 3.cmd is... Code: @echo off CD /d %~dp0 MD F:\delete robocopy.exe F:\ F:\delete /e /move /create /XD Whatever "System Volume Information" Recycler $Recycle.bin RD F:\delete /s /q robocopy.exe H:\ F:\ *.* /mir /XD Whatever "System Volume Information" Recycler $Recycle.bin /copy:DAT /dcopy:DA /r:0 /v /xj /mt:32
BATCH02 Using the same partitions. 4.cmd is... Code: @echo off RD F:\Y3 /s /q robocopy.exe H:\Y4 F:\Y3 *.* /mir /copy:DAT /dcopy:DA /r:0 /v /xj /mt:32
BATCH01 Using the same partitions. 5.cmd is... Code: @echo off MD F:\delete robocopy F:\ F:\delete /e /move /create /XD "System Volume Information" $Recycle.bin RD F:\delete /s /q robocopy.exe H:\ F:\ *.* /mir /XD "System Volume Information" $Recycle.bin /copy:DAT /dcopy:DA /r:0 /v /xj /mt:32
Hi Brian K! Firstly... thousand thanks to you for your great help!!!!!!!!!!!!!!! Since yesterday I'm following your answers, but I preferred to wait before replaying you, because I was testing line by line each one of your codes (in order to learn what each line exactly does). I tested everything (BATCH 01, 02 and 03), and in general everything works. I said "in general" because sometimes, here and there, a folder is not deleted or not copied. I don't know why. But again, in general, your batches are doing 99% of the job. Please, if you allow me, I have few simple questions, starting with BATCH01: 1. Comparing your BATCH01 to your BATCH03 (single batch file version), at BATCH01 you are not using "CD /d %~dp0". Do you confirm? 2. Again, comparing your BATCH01 to your BATCH03, the semantics changed a little, at BATCH03 we can see "Recycler $Recycle.bin", but in BATCH01 is "$Recycle.bin". Do you confirm? Thank you once again!
Decopi, I was using some of my old batch files and didn't notice.... CD /d %~dp0 is not necessary. Recycler is not necessary either. These entries will do no harm but aren't needed.
CD /d %~dp0 Can be useful in a batch file as it changes the path to the folder where you are running the batch file. This saves you from typing multiple long paths. For example... C:\Windows\System32 becomes D:\My_files\_IFLlatest\__tbs boot scripts start here RESTORES\brian diff restore C Files can now be easily accessed in that long path. %~dp0 is D:\My_files\_IFLlatest\__tbs boot scripts start here RESTORES\brian diff restore C Code: C:\Windows\System32>pause Press any key to continue . . . C:\Windows\System32>CD /d D:\My_files\_IFLlatest\__tbs boot scripts start here RESTORES\brian diff restore C D:\My_files\_IFLlatest\__tbs boot scripts start here RESTORES\brian diff restore C>pause Press any key to continue . . .
Perfect! Thanks. Please, two more simple questions about BATCH01: 1. Based on your code, at F: in BATCH01 I don't care about "System Volume Information" and "$Recycle.bin" folders. So, from my ignorance, I wonder: In order to make your batch faster, instead of "MD F:\delete" and "robocopy F:\ F:\delete /e /move /create /XD "System Volume Information" $Recycle.bin", what do you think if we replace that part in the batch with "format F:"? I never wrote a batch file, so I could be totally wrong! But I think that by (quick) formatting F:, it will avoid all the "copy/delete" part of your code, which perhaps will be faster with "quick format", and also less I/O on the SSD. Any thoughts? 2. Is it possible to make this BATCH01 to always run as "administrator"? Thks!!!!!!!!!!
I've never run "format" from a batch file. I right click and run most of my batch files as "Run as administrator".
I've used TBOSDT Pro from a batch file to delete and recreate partitions. I don't think I could do it from a Diskpart batch file. Only manually.
1. You could also use (quick) format, but it's all on your risk... For example, Format X: /FS:FAT32 /q 2. Depending on the version of windows you are using - there are already answers on stack about this How can I auto-elevate my batch file, so that it requests from UAC administrator rights if required?
Hi Dmitry_rus, I tested your code, unfortunately I couldn't make it work. It asks for name of the volume, and even when I write the name, it does nothing after it. However, googling the subject, I found something that works: Format F: /FS:NTFS /V:Whatever /Q /X /y Please, do you approve it? I never wrote a batch file. Again, I tested "Format F: /FS:NTFS /V:EM2 /Q /X /y" and it works. But I'm blind, I don't know what I'm doing. Please, is "Format F: /FS:NTFS /V:EM2 /Q /X /y" fine? Thks!
Please press Win+R, type "cmd" (without quotes) and press Enter. Then type "format /?" (without quotes) in the black console window. It will print out a list of format's parameters. Every command has built-in "help", so don't hesitate to use it.. V: means volume name, FS: type of file system, Q - quick formatting, /Y - start without confirmation (undocumented?). Your command mentioned above should work fine.
I appreciate tremendously that he was able to step in and help, I was unable to find the time and he is more experienced with this anyway.
normally batch = command line cannot delete those two folders because hidden and read only and not sufficient rights, messages need to verbosed. if your batch already do you have messed it up with them. and for copying files the command line is sooo slow...
Thank you for your replay. Do you have a better alternative than a batch? Something simple I can implement?
"attrib -h -s -r dir_or_filename" clears hidden/system/readonly attributes and file/directory can be deleted without problems (requires admin privileges). Robocopy with /mt:32 should work smooth enough.
There is a bug in Robocopy that can sometimes cause the target files/folders to be hidden after copying from the root of a partition. You didn't experience this bug and I haven't seen it for a long while. For example, copying to K:\House from M:\ When you look in K:\House there is "nothing". Fixed by... Code: attrib -s -h K:\House Now the files/folders are visible.
I backup my Data partition with images and Robocopy. There is 400 GB of data and a daily Robocopy backup takes 1 minute.
Please, may I ask you if your robocopy backup strategy is differential or incremental or anything else? Why do you prefer robocopy instead backup software? For specific backups, I can't use backup software nor backup windows. So, thanks to your great help, now I'm using batches. But it is kind of messy, because I have lot of drives, and some of my backups are too specific, with folders that shouldn't be deleted, or folders that don't need backup at all. Do you have similar situation with your backup strategy?