• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 66
  • Last Modified:

Move Profile Subfolders to new location

We have a profile repository D:\Profiles\*username*

Is it possible to script the MOVE of two partiuclar folders under the above directory to a new location using the same *username* parent folder?


D:\Profiles\jsmith\Downloads              MOVE TO                           D:\Profiles_Old\jsmith\Downloads

Having to do this for over 400 profiles, so automation and keeping the target folder under a parent folder with the username would be great
Daniel Diaz
Daniel Diaz
1 Solution
This should do the trick; it's in test mode and will only report what it would do.
Remove the uppercase ECHOs in lines 12 and 14 to run it for real.
@echo off
set Source=D:\Profiles
set Target=D:\Profiles_Old
set FolderList=Downloads Foo
for /d %%a in ("%Source%\*") do (
	echo Processing %%~nxa ...
	for %%f in (%FolderList%) do (
		echo   - %%~f ...
		if exist "%%a\%%~f" (
			if not exist "%Target%\%%~nxa" (
				ECHO md "%Target%\%%~nxa"
			ECHO move "%%a\%%~f" "%Target%\%%~nxa"
		) else (
			echo     ... not found.

Open in new window

Daniel DiazAuthor Commented:
Worked like a charm.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now