Computing.Net > Forums > Programming > Ensure that folder is empty

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Ensure that folder is empty

Reply to Message Icon

Name: MightyMe
Date: February 9, 2009 at 15:51:53 Pacific
OS: Windows 2003 SP2
Subcategory: Batch
Comment:

During my daily process, I need to move files from one folder to another and then kick off a data load. Before starting to move files to my target, I want to ensure that my target folder is empty. If it isn't, then I want to exit.
When I initially googled this, I got some help using the FOR command. However, that doesn't work (no idea why) on the Windows server at my client. I am looking for an alternative to using FOR.



Sponsored Link
Ads by Google

Response Number 1
Name: klint
Date: February 9, 2009 at 16:34:02 Pacific
Reply:

In what way does it "not work"? Do you get an error message? Are there any files (which ones?) in the folder that the FOR command doesn't find and it thinks it's empty?

Try this alternative:


if exist x:\folder\* (
echo Folder not empty.
exit /b 1
) else (
xcopy s:\source\* x:\folder
)

0

Response Number 2
Name: MightyMe
Date: February 9, 2009 at 21:54:58 Pacific
Reply:

When I say it doesn't work, the message it used to give is:

'for' is not recognized as an internal or external command, batch script etc.etc

When I tried 'for' today, it worked. But I will try your solution. I tried

if exist %target%\DET*.* (
echo something
exit 1
)
this worked.

Cheers


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Ensure that folder is empty

Check for Empty Main Folder www.computing.net/answers/programming/check-for-empty-main-folder/17014.html

Batch to check folder size www.computing.net/answers/programming/batch-to-check-folder-size/16184.html

How to do Searching ...? www.computing.net/answers/programming/how-to-do-searching-/9288.html