我有大量包含CSV和htm文件的文件夹。每个文件夹都有唯一的文件夹名称作为ID。我想知道是否有可能提取文件夹名称?
答案 0 :(得分:1)
对于任何目录路径字符串,您可以使用:
import UIKit
@IBDesignable class GenericXibView: UIView {
@IBInspectable var nibName:String?
/**
View name.
*/
func getNibName() ->String?
{
return nibName
}
/**
View itself.
*/
var vView : UIView!;
override func awakeFromNib() {
super.awakeFromNib()
self.setup()
}
/**
Class construct. Initialize the view.
*/
public override init(frame oFrame: CGRect) {
super.init(frame: oFrame);
self.setup();
}
/**
Class construct. Initialize the view.
*/
public required init?(coder oDecoder: NSCoder) {
super.init(coder: oDecoder);
self.setup();
}
/**
Initialize the custom view and add it to this.
*/
fileprivate func setup() {
assert(self.getNibName() != nil, "View with empty nib name can't be instatiated")
self.vView = UINib(nibName: self.getNibName()!, bundle: Bundle(for: type(of: self))).instantiate(withOwner: self, options: nil)[0] as! UIView;
self.vView.translatesAutoresizingMaskIntoConstraints = false;
self.addSubview(vView);
self.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[view]-0-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["view":self.vView]));
self.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-0-[view]-0-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["view":self.vView]));
// self.vImgUser.layer.cornerRadius = (self.vImgUser.frame.size.width / 2);
// self.vImgUser.layer.masksToBounds = true;
self.setNeedsLayout();
}
override func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
setup()
vView.prepareForInterfaceBuilder()
}
/*
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func draw(_ rect: CGRect) {
// Drawing code
}
*/
}
对于一系列目录:
fullpath = getwd()
directoryname = basename(fullpath)
你只需要省略"。"在manydirectories = list.dirs()
directorynames = basename(manydirectories)
中,然后获取该目录中的文件夹名称。