Batch script to delete content of sub folders

Hi

we have an FTP server with hundreds of users. Each user has sub folders, Each week I want to delete the content of the sub folders, but leave the content in the main root folder.

eg  C:\wsftp\ftp_users\jblogs\

jblogs1
jblogs2
jblogs3

the script I have so far is like this, which works and deletes the content of the subfolders.
How  can I change it to link to a text file with users, in line two, the user is jblogs, without having to run the script for each user.

@echo off
set topLevel=C:\wsftp\ftp_users\jblogs
cd /C %topLevel%
FOR /C  %%a IN (*) DO (
forfiles /P "%topLevel%\%%a" /S /M *.* /C -7 /C "cmd /C del @PATH"
cd /C  %topLevel%\%%a
for /f "delims=" %%i in ('dir /s /b /ad ^| sort /r') do rd "%%i">NUL
)

thanks

V
DavidfoleyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
That script is most certainly not working; what are all the "/C" doing in there? Did you do a search and replace of /D to /C?
Anyway, this should do what you want. It's in test mode and will only echo out the delete commands it would normall run. Delete the two uppercase ECHOs in lines 7 and 9 to run it for real.
@echo off
set UserList=C:\Temp\users.txt
set topLevel=C:\wsftp\ftp_users
for /f "delims=" %%u in ('type "%UserList%"') do (
	cd /D "%topLevel%\%%~u"
	FOR /D %%a IN (*) DO (
		forfiles /P "%topLevel%\%%~u\%%a" /S /M *.* /D -7 /C "cmd /C ECHO del @PATH"
		cd /D "%topLevel%\%%~u\%%a"
		for /f "delims=" %%i in ('dir /s /b /ad ^| sort /r') do ECHO rd "%%i">NUL
	)
)

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DavidfoleyAuthor Commented:
Thanks, works perfect!
DavidfoleyAuthor Commented:
Excellent solution
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.