Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
DOS/Other
Tag Cloud
access acer asus bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop malware memory modem monitor motherboard mouse network printer problem ram registry repair router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > DOS/Other >
Batch file help for subfolder

Reply  
Thread Tools
daniel50096230's Avatar
Junior Member with 3 posts.
 
Join Date: Aug 2009
10-Aug-2009, 06:31 AM #1
Batch file help for subfolder
I have the following code in my batch file, but currently the batch file only copy and move any file that end with extension .txt to other folder. But I would like to check whether inside my New Folder, is there any other subfolders. If yes,then it should retrieve the file from the subfolders and copy to other folder.May I know how can I do that?


Code:
echo %date% %time% >>C:\JnJ.txt
XCOPY /y C:\New Folder\*.txt C:\New Folder (2)\
move /y C:\New Folder\*.txt C:\
Squashman's Avatar
Trusted Advisor with 18,706 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
10-Aug-2009, 01:33 PM #2
You would have to put it into a for loop.
Code:
For /F "tokens=*" %%A in ('dir /b /s "C:\New Folder\*.txt"') do (
     xcopy /y "%%A" "C:\New Folder (2)"
     move /y "%%A" C:\
     )

Last edited by Squashman; 10-Aug-2009 at 01:59 PM..
daniel50096230's Avatar
Junior Member with 3 posts.
 
Join Date: Aug 2009
10-Aug-2009, 09:39 PM #3
Thanks. Is there anyway to delete the directory after finished copy the file??
TheOutcaste's Avatar
Computer Specs
Distinguished Member with 9,048 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
11-Aug-2009, 01:17 AM #4
Add this as the last line, after everything is copied:
RD /S /Q "C:\New Folder"
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 01:12 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.