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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 70

Accepted Solution

Qlemo earned 500 total points
ID: 36550477
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

ID: 36564913
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Insert parts by customer 12 63
Output in PHP throwing alignment of data off issue 12 76
learn programming 8 95
batch file or script 4 66
This is an explanation of a simple data model to help parse a JSON feed
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

710 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