SPFx has some utility classes to help you get the folder url. Its not available in pageContextInfo
or any other page property. However, you can split it from the query string's Id parameter.
Add the below import statement:
import { Log, UrlQueryParameterCollection } from '@microsoft/sp-core-library';
And in your execution logic, use it as:
@override
public onExecute(event: IListViewCommandSetExecuteEventParameters): void {
var queryParameters = new UrlQueryParameterCollection(window.location.href);
var current_folder_path= url_query_param.getValue("Id") || url_query_param.getValue("RootFolder");
if (queryParameters.getValue("Id")) {
var folderUrl = decodeURIComponent(current_folder_path);
Dialog.alert(`${folderUrl}`);
}
}
End result - in the Shared Document library, have created a folder named Test: