[英]How to check the length of the directory in javascript
I have two different directories like 我有两个不同的目录,例如
My requirement is dir 1 has all the js files, css files, icons etc.. but dir 2 will have only html file with same name like dir 1 html files. 我的要求是目录1具有所有js文件,css文件,图标等。但是目录2将仅具有同名的html文件,例如目录1 html文件。
Based on different domains on page load i need to make a decision which html needs to load. 基于页面加载的不同域,我需要确定需要加载哪个html。
I am using require js "text", I want to make the path of the text!path
more dynamic. 我正在使用require js“ text”,我想使
text!path
更动态。
Inside directory2 i want to check the length first, and then I want to pick the file. 在directory2内部,我想先检查长度,然后再选择文件。
Please suggest me a approach on this. 请给我建议一个解决方法。
I'm not sure if this is what you mean "check the length of the directory", Use split(). 我不确定这是否是您的意思“请检查目录的长度”,请使用split()。
var directory = 'dir0/dir1/dir2';
var directories = directory.split('/');
var count = directories.length;
Use Like this Way to check URL contains folder or File.. 使用“以这种方式”检查URL包含文件夹或文件。
function isFile(pathname) {
return pathname
.split('/').pop()
.split('.').length > 1;
}
function isDir(pathname) { return !isFile(pathname); }
console.log(isFile(document.location.pathname));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.