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
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.
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.
Summary: Hi! I would like to check whether a main folder is empty. Here what I did, get a list of files and subdirectories from the main folder using dir write it to text file. Then I check on the text file fo...
Summary: Ok, if you can't tell, I'm a little new to this. It looks like it's doing exactly what I need. Here is the batch with edits to work in my environment: @echo off :loop dir/a-d/b c:\staging> nul 2>nu...
Summary: Dim Sele as string if Text1.text <> "" then Sele = "select * from student where Name LIKE '" & Text1.Text & "%'" else Sele = "select * from student where phono=" & opt1 end if Set rec = Yourdatabas...