I have gone through the questions in this forum and most of them address the Issue of how to check whether a folder exists in a Document Library. But, I would like to know how to check whether a folder is empty using PNP-JS

    sp: {
        fetchClientFactory: () => new NodeFetchClient(creds),
        baseUrl: "",
        spfxcontext: this.context

    .then(data => {
        console.log(`Your web title: ${data.Title}`);

You need to use a CAML Query to get the items in the folder. Once you do you can check to see of the length of the results array is zero.

let query: CamlQuery = {
    ViewXml: "<View></View>",
    FolderServerRelativeUrl: "/sites/<site>/<list>/<folder>"

sp.web.lists.getByTitle("<list name>").getItemsByCAMLQuery(query).then((results) => {
    // ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.