Get-child项Lastwritetime未正确返回

时间:2018-01-12 22:54:40

标签: powershell get-childitem

我正在尝试使用CreationTime命令获取Lastwritetimeget-childitem并将其与相同的装配时间进行比较,以检查每5分钟是否有任何差异。

奇怪的是,如果程序集没有更改并且导致compare-object失败,那么每次获取记录时都会有毫秒差异。

除了将时间转换为字符串格式之外,还有什么方法可以解决这个问题吗?

下面是获取程序集详细信息的命令

Get-ChildItem -Path 'C:\Windows\Microsoft.NET\assembly\GAC_MSIL' -include *.dll -Recurse|select @{Label=”AssemblyName”;Expression={$_.Name}},@{Label=”Size”; Expression={$_.Length}},@{label="Version";expression={if($_.versioninfo.productversion -eq $null) { 
              "NULL"
            } else { 
              $_.versioninfo.productversion
            }
          }},@{Label=”CreationTime”; Expression={$_.CreationTime}},@{Label=”LastWriteTimeUtc”; Expression={$_.LastWriteTimeUtc}}

并在5分钟后运行此命令并与compare-object进行比较

compare-object -$oldobject $newObject -property Name,Lastwritetime

1 个答案:

答案 0 :(得分:0)

我不知道为什么存在相差几毫秒的确切原因(最可能是inaccurate floating point number)。

像这样的问题的通常解决方案是在比较中使用epsilon值(在游戏编程中非常常见)。

import UIKit
import Firebase
import FirebaseStorageUI

class TableViewController: UITableViewController {
var images:[UIImage]! = [#imageLiteral(resourceName: "rininger_2.jpg")]
var imageURLS:[String] = [String]()
var listener:ListenerRegistration?

override func viewDidLoad() {
    super.viewDidLoad()

    /////////
    listener = Firestore.firestore().collection("Posts").addSnapshotListener{
        querySnapshot, error in
        guard let snapshot = querySnapshot else {
            print("Error fetching snapshots: \(error!)")
            return
        }
        snapshot.documentChanges.forEach { diff in
            if (diff.type == .added) {
                print("New data: \(diff.document.data())")
            }
            if (diff.type == .modified) {
                print("Modified city: \(diff.document.data())")
            }
            if (diff.type == .removed) {
                print("Removed city: \(diff.document.data())")
            }
            // self.numberOfRows = snapshot.count
            // Parse each post


            //self.labels.append(newLabel)


            //Update TableView
            DispatchQueue.main.async {
                //This would reload everything creating a flash
                //self.tableView.reloadData()
                guard let newImageURL = diff.document.data()["imageDownloadURL"] as? String else{
                    print("Failed to get image download URL")
                    return
                }
                //let newLabel = Post(snapshot:diff.document)
                print("downloadURL: \(newImageURL)")
                self.imageURLS.insert(newImageURL, at: 0)
                let indexPath = IndexPath(row: 0, section: 0)
                self.tableView.insertRows(at: [indexPath], with: .top)

            }
        }
    /////////
    }
}


override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

// MARK: - Table view data source

override func numberOfSections(in tableView: UITableView) -> Int {
    // #warning Incomplete implementation, return the number of sections
    return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete implementation, return the number of rows
    return imageURLS.count
}


override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "Reuse", for: indexPath) as! TableViewCell

    // Configure the cell...

    ///////////////////////
        let downloadURL = URL(string: imageURLS[indexPath.row])

            //cell.cellImageView.sd_setImage(with: downloadURL, completed:nil)
            //cell.cellImageView.image = self.images[indexPath.row]
    do{
        let imageData = try Data(contentsOf: URL(string:(imageURLS[indexPath.row]))!)
        cell.cellImageView.image = UIImage(data: imageData)
    }
    catch{
        print("unable to load data: \(error)")
    }
            cell.cellImageView.contentMode = .scaleAspectFit
            let aspectRatio = Float((cell.cellImageView?.image?.size.width)!/(cell.cellImageView?.image?.size.height)!)
            tableView.rowHeight = CGFloat(Float(UIScreen.main.bounds.width)/aspectRatio)

    ///////////////////////
    return cell
 }
}
  


  假
  假

根据需要调整epsilon值。 (遵守数字限制)