Instead of SPServices you can use my JavaScript API called SharepointPlus (see at the end if you want to keep SPServices).
Two ways to do what you want:
- get ALL the structure of your library,
- or get just the folder clicked by the user
With the first option you can call the below code only once, and then you'll have to store the structure somewhere:
$SP().list("Shared Documents Library").get({
fields:"BaseName,FileRef,FSObjType", // "BaseName" is the name of the file/folder; "FileRef" is the full path of the file/folder; "FSObjType" is 0 for a file and 1 for a folder (you need to apply $SP().cleanResult())
folderOptions:{
show:"FilesAndFolders_Recursive"
}
}, function(files) {
// in "files" you have ALL the files and folders in your library
for (var i=0; i<files.length; i++) {
console.log(files[i].getAttribute("FileRef"))
}
});
For the second option, you'll have to call the below code each time the user clicks on a folder. For example if he clicks on "Folder #1":
$SP().list("Shared Documents Library").get({
fields:"BaseName,FileRef,FSObjType", // "BaseName" is the name of the file/folder; "FileRef" is the full path of the file/folder; "FSObjType" is 0 for a file and 1 for a folder (you need to apply $SP().cleanResult())
folderOptions:{
show:"FilesAndFolders_InFolder", /* this option changed from 1) */
path:"Folder #1" /* here is the name of the folder */
}
}, function(files) {
// it will get the files and folders into the "Folder #3"
for (var i=0; i<files.length; i++) {
console.log(files[i].getAttribute("FileRef"))
}
});
If you don't want to use SharepointPlus, with SPServices, you'll have to define the queryOptions for your query. If you use option 1 (above) then your queryOptions will look like that:
<QueryOptions>
<ViewAttributes Scope="RecursiveAll"></ViewAttributes>
<Folder>http://your.siteweb.com/path/to/site/collection/path/to/Folder #1</Folder>
</QueryOptions>
To know which ViewAttributes Scope to use you can check my code.