private void FileAttrForm_Load(object sender, EventArgs e) { this.Text = file.getFilename() + " 的属性"; if (file.getAttrs().isDir()) { text_type.Text = "文件夹"; icon.BackgroundImage = Properties.Resources.folder_64px; } else { text_type.Text = getFileExt(file.getFilename()); icon.Image = Properties.Resources.filen_64px; } text_name.Text = file.getFilename(); text_size.Text = Utils.getFileSize(file.getAttrs().getSize()); text_host.Text = user.Host; text_location.Text = dir + file.getFilename(); text_modified.Text = file.getAttrs().getMtimeString(); text_owner.Text = getFileOwner(file.getLongname(), 3); text_group.Text = getFileOwner(file.getLongname(), 4); text_permiss.Text = file.getAttrs().getPermissionsString(); }
public void LoadDirFilesToListView(string path, LoadFilesResult result = null) { this.BeginInvoke((MethodInvoker) delegate() { try { if (null == sftpChannel) { return; } ArrayList files = sftpChannel.ls(path); if (files != null) { ChannelSftp.LsEntry file = null; listView2.Items.Clear(); LargeImages.Images.Clear(); SmallImages.Images.Clear(); LargeImages.Images.Add(Properties.Resources.filen_64px); LargeImages.Images.Add(Properties.Resources.folder_64px); SmallImages.Images.Add(Properties.Resources.filen_16px); SmallImages.Images.Add(Properties.Resources.folder_16px); ListViewItem item = null; ListViewItem.ListViewSubItem subItem = null; List <ListViewItem> itemList = new List <ListViewItem>(); for (int i = 0; i < files.Count; i++) { object obj = files[i]; if (obj is ChannelSftp.LsEntry) { file = (ChannelSftp.LsEntry)obj; if (file.getFilename() == ".") { continue; } item = new ListViewItem(); item.Text = file.getFilename(); item.Tag = file; if (file.getFilename() != "..") { subItem = new ListViewItem.ListViewSubItem(); subItem.Text = Utils.getFileSize(file.getAttrs().getSize()); item.SubItems.Add(subItem); subItem = new ListViewItem.ListViewSubItem(); subItem.Text = file.getAttrs().isDir() ? "文件夹" : file.getAttrs().isLink() ? "快捷方式" : getFileExt(file.getFilename()); item.SubItems.Add(subItem); subItem = new ListViewItem.ListViewSubItem(); subItem.Text = file.getAttrs().getMtimeString(); item.SubItems.Add(subItem); subItem = new ListViewItem.ListViewSubItem(); subItem.Text = file.getAttrs().getPermissionsString(); item.SubItems.Add(subItem); subItem = new ListViewItem.ListViewSubItem(); subItem.Text = getFileOwner(file.getLongname()); item.SubItems.Add(subItem); item.ImageIndex = file.getAttrs().isDir() ? 1 : 0; if (file.getAttrs().isDir()) { listView2.Items.Add(item); } else { itemList.Add(item); } } else { subItem = new ListViewItem.ListViewSubItem(); subItem.Text = ""; item.SubItems.Add(subItem); subItem = new ListViewItem.ListViewSubItem(); subItem.Text = ""; item.SubItems.Add(subItem); subItem = new ListViewItem.ListViewSubItem(); subItem.Text = ""; item.SubItems.Add(subItem); subItem = new ListViewItem.ListViewSubItem(); subItem.Text = ""; item.SubItems.Add(subItem); subItem = new ListViewItem.ListViewSubItem(); subItem.Text = ""; item.SubItems.Add(subItem); item.ImageIndex = 1; listView2.Items.Add(item); } } } foreach (ListViewItem item2 in itemList) { listView2.Items.Add(item2); } if (null != result) { result(); } } else { MessageBox.Show(this, "目录不存在", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception e) { logger.Error("加载数据失败:" + e.Message, e); if (!success) { sftpForm.CloseTab(this); } } }); }