Expert Qlemo or others Expert How do I move C:\Windows\$NtUninstall to another folder using a batch file?

Posted on 2011-09-15
Last Modified: 2012-05-12
I have this batch file without the /MOVE option, I would like to include it in order to move the target folder, and their contain files

In order words
I need a code WHICH
MOVE WITH the criteria to "all folders C:\Windows\$*, but not $hf_mig$" AND their contents of each folders TO C:\Backup\NtUninstall\
IF all folders FROM C:\Windows\$*, but not $hf_mig$" AND their contents (are) MOVE TO C:\Backup\NtUninstall\ I will NOT have to have at C:\Windows\ any folder that start WITH "$" except the folder $hf_mig$ and the folder's contains of the MOVEd TO C:\Backup\NtUninstall\

pushd %SystemRoot%
for /F "tokens=*" %%D in ('dir $* /b /a:d ^| find /v "$hf_mig$" ') do (
   md C:\Backup\NTUninstall\%%~nxD 2>nul
   robocopy "%%~D\" "C:\Backup\NtUninstall\%%~nxD" /MOVE
   rd "%%~D" 2>nul

Open in new window

Question by:rebelscum0000
LVL 68

Accepted Solution

Qlemo earned 500 total points
Comment Utility
After some minor corrections, the script runs as expected:
pushd %SystemRoot%
for /F "tokens=*" %%D in ('dir $* /b /a:d ^| find /v "$hf_mig$" ') do (
   md C:\Backup\NTUninstall\%%~nxD 2>nul
   robocopy "%%~D" "C:\Backup\NtUninstall\%%~nxD" /MOVE /E
   rd "%%~D" 2>nul

Open in new window

The corrections are:
* removed backslash from robocopy source folder name (you took the wrong code, it's already corrected in the other question)
* added /E to robocopy options
* added popd at the end of file
That's all what has been needed.

Author Closing Comment

Comment Utility
Excellent!!, That is what I want, the batch file MOVES all the folders and their contents FROM C:\Windows\$*, but not $hf_mig$ to another location in this case C:\Backup\NTUninstall\

Thank you very much

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup". After a while, you have entered a loop for Auto repair which does not fix anything and you will be in a  panic as all your work w…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now