Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Copy only subfolders to a new location

25 Sep 2015   #1
skoller

Windows 7 32bit
 
 
Copy only subfolders to a new location

Hello,
it's time to cleanup my pc and now I got stuck on the following:
I have the following structure:

D: Drive

->Folder1
->Folder2
->Subfolder1
->Folder3
->Folder4
->Subfolder2
(...)


Now I'd like to copy only all Subfolders (including the content) of Drive D.
I tried to find a solution with robocopy and windowssearch but didn't have any success.

Thanks for any help in advance

Skoller


My System SpecsSystem Spec
.
26 Sep 2015   #2
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Give this a try, sir.

th-382167.bat
Code:
@echo off
::
set "source=D:\"
set "match=subfolder*"    &rem Non case sensitive match
set "destination=C:\Users\%USERNAME%\Desktop\DestinationFolder"
::
pushd %SOURCE% || exit /b 1
for /f "delims=" %%I in (' dir /a:d-s /b . ') do (
	echo.%%~nxI| find "%MATCH:"=%" /i >NUL && (
		xcopy "%%~fI" "%DESTINATION:"=%\%%~nxI" /e /i /h /y >NUL
	)
)
robocopy "%SOURCE:\=\\%" "%DESTINATION:"=%" >NUL
attrib "%DESTINATION:"=%" -h -s
popd
It copies the folders that match "subfolder*" under D:\ and also copies all files under D:\.
My System SpecsSystem Spec
29 Sep 2015   #3
skoller

Windows 7 32bit
 
 

Hello,
thank you for your help. I tried the code and adapted it in several ways but unfortunately I can't get it to work.
Right now, it copies only the files in "D:\".
It looks like that "match" doesn't find any proper folder.
If it helps, I don't need a perfect match for "subfolder". It would be even better if there is a way to copy every subfolder - if there is one.
Thanks a lot for any hint in advance.
Skoller
My System SpecsSystem Spec
.

29 Sep 2015   #4
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

I'm sorry, sir, but you're going to have to express your problem more clearly. I'm losing track of what you're trying to do?
My System SpecsSystem Spec
30 Sep 2015   #5
skoller

Windows 7 32bit
 
 

Hello,
thanks for your reply. I think an example makes it clear:

My source looks like this::

Folder1
--->Data.txt
FolderX
--->Data.txt
Folder2
--->Subfolder1
--->SubData.txt
FolderY
--->SubfolderY
--->SubData.txt
Now I'd like to have a script which copies only the Subfolders including the data, so the result looks like this:


Target:

Subfolder1
---> SubData.txt
SubfolderY
---> SubData.txt
Hope this example makes my problem easier to understand.
Thanks a lot for any help and best regards
Stefan
My System SpecsSystem Spec
30 Sep 2015   #6
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Ah, I know exactly what you wish to accomplish now.

Too easy. Here you are, sir.


th-382167_2.bat
Code:
@echo off
::
set "source=D:\"
set "destination=C:\Users\%USERNAME%\Desktop\DestinationFolder"
::
pushd %SOURCE% || exit /b 1
for /f "delims=" %%I in (' dir /a:d-s /b . ') do (
    xcopy "%%~fI" "%DESTINATION:"=%" /e /i /h /y
)
xcopy . "%DESTINATION:"=%" /i /h /y
attrib "%DESTINATION:"=%" -h -s
popd
My System SpecsSystem Spec
30 Sep 2015   #7
skoller

Windows 7 32bit
 
 

Works great! Thanks a lot for your help.
My System SpecsSystem Spec
Reply

 Copy only subfolders to a new location




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
How to Copy-As-Path to include Subfolders & files?
is there a way to "expand" on the Copy-as-path idea to also copy the paths of all subfolders & files? I don't mean to actually change Copy-as-path itself, but accomplish the task of copying the paths of all subordinate items.
General Discussion
Can delete or open file, but cant copy it to any location
So i have a file, a .cab extension, i can open it via winrar and saw the properties of that file, also i can delete it to recycle bin, but i cant copy that file to another location in same hdd or to my external hdd. Already run chkdsk and 0 bad sector in my ext hdd and the hdd that contain that...
Performance & Maintenance
help scripting way to copy/rename one file to subfolders
i have a bunch of files on F: drive. There are many subfolders. i have one file called 'F:\master' whos data i want to copy to another file within the subfolders having some unknown name- the only thing i know is the suffix of the file name. so i have folders a, b, c, d, and so on. within each...
General Discussion
Location - Change Computer Default Location
How to Change the Default Location of your Windows 7 Computer This will show you how to set a default location to provide programs information about your computer's geographic location to use when a location sensor, such as a GPS receiver, is unavailable or not installed. When you set a default...
Tutorials
Saving to a library location that is NOT the default save location
OK, I've googled and searched for this as much as I can. I'm a new Windows 7 user. I have a library (Documents) with three folders included. Call them folders A, B, and C. I understand how to set the default save location. Let's say I've set it to Folder A. Now, I want to save a file in *Folder B*...
General Discussion
Copy location problems
i have strange problem on my win7 so when i try to unzip a file on one disk partition it automaticaly transfer that file on partition where is my windows instaled...its pretty annoing cause i have so much space on my other partition but it constantly transfers files on partition where windows is...
BSOD Help and Support


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 14:48.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App