void RefreshLocalListView() { var filePath = textBox1.Text; List <ListInfo> listInfos = new List <ListInfo>(); if (!string.IsNullOrEmpty(filePath) && filePath != "我的电脑") { try { var dir = new DirectoryClass() { FullName = filePath }; _driverHelper.GetDirectoryAndFile(dir); } catch (Exception ex) { Log("访问本地目录:" + filePath, ex.Message); } } else { try { _driverHelper.GetLocalDriver(); } catch (Exception ex) { Log("访问本地目录:" + filePath, ex.Message); } } }
/// <summary> /// 设定标题头,只针对固定的硬盘 /// </summary> private void FixDriverColumnHeader() { //重新加项目的列 if (CustomerChoose == CustomerViewList.平铺) { foreach (ListViewItem lst in _localListView.Items) { _localListView.Columns[0].Width = 180; //lst.SubItems[1].Text = ""; lst.SubItems[2].Text = ""; lst.SubItems[3].Text = ""; } } else { foreach (ListViewItem lst in _localListView.Items) { DirectoryClass dc = lst.Tag as DirectoryClass; lst.SubItems[1].Text = "本地磁盘"; lst.SubItems[2].Text = dc.MaxLength + "GB"; //修改日期 lst.SubItems[3].Text = dc.FreePrice + "GB"; // } } }
private void listView2_MouseDoubleClick(object sender, MouseEventArgs e) { if (listView2.SelectedItems.Count <= 0) { return; } string typeName = listView2.SelectedItems[0].SubItems[1].Text; if (typeName == "文件夹" || typeName == "本地磁盘") { DirectoryClass dir = listView2.SelectedItems[0].Tag as DirectoryClass; Task.Run(() => { try { if (_client.ChangeDir(dir.Name)) { var cp = _client.CurrentDir(); textBox2.Invoke(new Action(() => { textBox2.Text = cp; })); } else { textBox2_TextChanged(null, null); } } catch (Exception ex) { Log("获取ftpserver列表失败", ex.Message); } }); } else { Task.Run(() => { try { if (_client.ChangeToParentDir()) { var cp = _client.CurrentDir(); textBox2.Invoke(new Action(() => { textBox2.Text = cp; })); } } catch (Exception ex) { Log("获取ftpserver列表失败", ex.Message); } }); } }
public async Task <IHttpActionResult> GetDirectoryByPath(string path = "") { DirectoryClass directory = await _driveService._getInfo(path); if (directory == null) { return(NotFound()); } return(Ok(directory)); }
private static int Main(string[] args) { if (args.Length == 0) { args = DEFAULT_ARGS; } // Connect to the directory with your current // domain under your credentials . Directory psDirectory = new DirectoryClass(); try { psDirectory.Connect("", "", ""); Product psProduct = psDirectory.GetProductByName("Singularity"); Datastore psDataStore = psProduct.Connect("", "", ""); TestExporter t = new TestExporter(psDirectory, psDataStore); switch (args[0]) { case "-i": if (args.Length < 2) { break; } t.ImportProfile(args[1]); t.Report(); return(0); case "-o": if (args.Length < 3) { break; } t.ExportProfile(args[1], args[2]); return(0); case "-h": t.QueryTestCases(); return(0); default: break; } Console.WriteLine("Usage: TestExport -i <testprofile> | -o <testType> <testprofile>"); return(-1); } catch (Exception e) { Console.WriteLine("Error: {0}", e.Message); return(-1); } finally { psDirectory.Disconnect(); } }
public void InitializeSession(Session session) { this.session = session; Console = new ConsoleClass(session); Environment = new EnvironmentClass(session); Path = new PathClass(session); File = new FileClass(session); Directory = new DirectoryClass(session); Thread = new ThreadClass(session); Process = new ProcessClass(session); }
public async Task <IHttpActionResult> GetDirectoriesInfo(PathClass current) { DirectoryClass directory = await _driveService._getInfo(current.path); var data = new List <DirectoryClass> { }; data.Add(directory); if (data == null) { return(null); } return(Ok(directory)); }
// [Route("GetDirectory/{path?}")] public async Task <List <DirectoryClass> > GetDirectory(PathClass path) { string url = string.Empty; try { url = path.path; } catch { url = ""; } // DirectoryClass directory = await _driveService._get(path); DirectoryClass directory = await _driveService._getNames(url); var resultdata = new List <DirectoryClass> { }; resultdata.Add(directory); if (resultdata == null) { return(null); } return(resultdata); }
private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { directory = null; directoryInfo = null; _path = null; } // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. // TODO: set large fields to null. disposedValue = true; } }
public async Task <IHttpActionResult> openParrent(PathClass dir) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } DirectoryClass Dir = await _driveService._getInfo(dir.parrentPath); List <DirectoryClass> directory = new List <DirectoryClass> { }; directory.Add(Dir); if (directory == null) { return(null); } return(Ok(directory)); }
private void btnRevise_Click(object sender, System.EventArgs e) { DirectoryClass dc = new DirectoryClass(); try { dc.Revise(Int32.Parse(ClassID), this.txtAClassName.Text, this.txtAClassName.Text, 1, 100, DateTime.Today, DateTime.Today); Response.Write("<script language=javascript>alert('修改成功!');parent.LeftFrame.location='ProjectTreeView.aspx?classID=" + ClassID + "';</script>"); } catch (Exception ex) { UDS.Components.Error.Log(ex.ToString()); Server.Transfer("../Error.aspx"); } finally { dc = null; } }
public void RefreshListView(string _funcPath, ListView LW) { LW.Items.Clear(); //Заповнюємо рядки-папки string[] a = Directory.GetDirectories(_funcPath); foreach (string b in a) { DirectoryClass dir = new DirectoryClass(b); ListViewItem lvi = new ListViewItem(b); lvi.SubItems.Add(dir.GetName()); lvi.SubItems.Add(@"Папка"); LW.Items.Add(lvi); } //Заповнюємо рядки-файли a = Directory.GetFiles(_funcPath); int slashPos = -1, pointPos = -1; long length = -1; foreach (string b in a) { FileClass file = new FileClass(b); slashPos = b.LastIndexOf('\\'); // EXC: тут slashPos может быть равен -1 pointPos = b.LastIndexOf('.'); ListViewItem lvi = new ListViewItem(b); lvi.SubItems.Add(file.GetName()); lvi.SubItems.Add(file.GetExtension()); length = (new FileInfo(b).Length + 1000) / 1000; lvi.SubItems.Add(length.ToString() + @" Kb"); LW.Items.Add(lvi); } }
/// <summary> /// <para> /// Initializes a new instance of the <see cref="BookListMainWin" /> /// </para> /// <para>class.</para> /// </summary> public BookListMainWin() { InitializeComponent(); var declaringType = MethodBase.GetCurrentMethod().DeclaringType; if (declaringType != null) { _msgBox.NameOfClass = declaringType.Name; } var authorOp = new AuthorOperationsClass(); var dirFile = new FileClass(); var dirClass = new DirectoryClass(); dirClass.InitializeDirectoryPath(); dirFile.InitializeFilePaths(); authorOp.UpdateAuthorsNamesWithFileNames(); }
private void listView1_MouseDoubleClick(object sender, MouseEventArgs e) { if (listView1.SelectedItems.Count <= 0) { return; } string typeName = listView1.SelectedItems[0].SubItems[1].Text; if (typeName == "文件夹" || typeName == "本地磁盘") { DirectoryClass dir = listView1.SelectedItems[0].Tag as DirectoryClass; listView1.Items.Clear(); _driverHelper.GetDirectoryAndFile(dir); textBox1.Text = dir.FullName; } else { FileClass file = listView1.SelectedItems[0].Tag as FileClass; Process.Start(file.FullName); } }
/// <summary> /// 得到磁盘的资料 /// </summary> public void GetLocalDriver() { _localListView.Clear(); _localListView.Columns.Add("columnsName", "名称", 200); _localListView.Columns.Add("columnsType", "类型", 80); _localListView.Columns.Add("columnsMax", "总大小", 100); _localListView.Columns.Add("columnsFreeSpace", "可用空间", 80); FixDriverColumnHeader(); foreach (DriveInfo driver in DriveInfo.GetDrives()) { if (driver.DriveType == DriveType.Fixed) //如果是硬盘 { DirectoryClass driverBase = new DirectoryClass(); driverBase.Name = driver.Name; driverBase.FullName = driver.Name; driverBase.IsDirectory = true; driverBase.FreePrice = Math.Round((driver.TotalFreeSpace / 1024.0 / 1024.0 / 1024.0), 1); //可用空间 driverBase.MaxLength = Math.Round((driver.TotalSize / 1024.0 / 1024.0 / 1024.0), 1); //总大小 ListViewItem item = new ListViewItem(); item.Text = string.Format("{0}({1})", driver.VolumeLabel, driver.Name); item.Tag = driverBase; item.ImageIndex = _sysIcons.SmallImageList.Images.IndexOfKey("MyDriver"); //子项 item.SubItems.Add("本地磁盘"); //类型 item.SubItems.Add(driverBase.MaxLength + "GB"); //可用空间 item.SubItems.Add(driverBase.FreePrice + "GB"); _localListView.Items.Add(item); } } }
/// <summary> /// 填充文件夹的标题头 /// </summary> private void FillRemoteDirectoryHeader() { if (CustomerChoose == CustomerViewList.平铺) { foreach (ListViewItem lst in _remoteListView.Items) { _remoteListView.Columns[0].Width = 200; //lst.SubItems[1].Text = ""; lst.SubItems[2].Text = ""; lst.SubItems[3].Text = ""; } } else { _remoteListView.Columns.Add("columnsName", "名称", 200); _remoteListView.Columns.Add("columnsType", "类型", 200); _remoteListView.Columns.Add("columnsMax", "修改日期", 150); _remoteListView.Columns.Add("columnsFreeSpace", "大小", 80); foreach (ListViewItem lst in _remoteListView.Items) { if (lst.SubItems[1].Text == "文件夹") { DirectoryClass dc = lst.Tag as DirectoryClass; lst.SubItems[1].Text = "文件夹"; lst.SubItems[2].Text = dc.CreateTime1; //修改日期 } else { FileClass dc = lst.Tag as FileClass; lst.SubItems[1].Text = dc.FileExtendsName; //文件类型 lst.SubItems[2].Text = dc.CreateTime1; //修改日期 lst.SubItems[3].Text = dc.FileMax + "MB"; //大小 } } } }
public ClassContext Get(string path) { List <string> disks = new List <string>(); List <string> directories = new List <string>(); List <string> files = new List <string>(); db.Directories = new List <DirectoryClass>(); db.Files = new List <FileClass>(); if (path == null || path == "null") { foreach (DriveInfo item in DriveInfo.GetDrives()) { if (item.IsReady) { disks.Add(item.ToString()); } } directories.AddRange(disks); for (var i = 0; i < directories.Count; i++) { string str = directories[i]; DirectoryClass dir = new DirectoryClass() { Name = str, Path = str }; db.Directories.Add(dir); } db.small_count = 0; db.middle_count = 0; db.big_count = 0; db.FolderUpPath = null; db.FolderUpSign = null; return(db); } DriveInfo drives = new DriveInfo(path); if (!drives.IsReady) { path = String.Empty; return(Get(path)); } if (System.IO.File.Exists(path)) { var lastIndex = path.LastIndexOf("\\"); path = path.Substring(0, lastIndex); } directories.AddRange(Directory.GetDirectories(path)); for (var i = 0; i < directories.Count; i++) { string fullName = directories[i]; var lastIndex = directories[i].LastIndexOf("\\"); string name = fullName.Substring(lastIndex + 1); DirectoryClass dir = new DirectoryClass() { Name = name, Path = fullName }; db.Directories.Add(dir); } files.AddRange(Directory.GetFiles(path)); for (var i = 0; i < files.Count; i++) { string fullName = files[i]; var lastIndex = files[i].LastIndexOf("\\"); string name = fullName.Substring(lastIndex + 1); FileClass file = new FileClass() { Name = name, Path = fullName }; db.Files.Add(file); } int[] count = FilesCount(path); db.small_count = count[0]; db.middle_count = count[1]; db.big_count = count[2]; string[] tmpList = path.Split(new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries); if (tmpList.Count() == 2) { db.FolderUpPath = path.Substring(0, path.LastIndexOf("\\") + 1); } else if (tmpList.Count() > 1) { db.FolderUpPath = path.Substring(0, path.LastIndexOf("\\")); } else { db.FolderUpPath = null; } db.CurrentPath = path; db.FolderUpSign = ".."; return(db); }
/// <summary> /// 根据节点信息,得到文件夹和文件,把显示到ListView列表中 /// </summary> /// <param name="info"></param> public void GetDirectoryAndFile(DirectoryClass info) { var action = new Action(() => { _localListView.Clear(); DirectoryInfo dirs = new DirectoryInfo(info.FullName); if (dirs.ToString() == @"C:\Documents and Settings\Administrator\桌面") { return; } //循环添加文件夹 foreach (DirectoryInfo dir in dirs.GetDirectories()) { if (dir.Name == "$RECYCLE.BIN" || dir.Name == "System Volume Information") { continue; } #region 如果文件是只读的就不要读出来,不然会报错 string[] fileAttrites = File.GetAttributes(dir.FullName).ToString().Split(','); //如果属性大于0的就说明有问题,只要属性里面有hidden就不要显示出来 bool isHideen = false; //是不是隐藏文件 foreach (string cAttrites in fileAttrites) { if (cAttrites.Equals("hidden", StringComparison.InvariantCultureIgnoreCase)) { isHideen = true; break; } } #endregion #region 判断isHideen=false,这样就可以添加资料到ListView中去 if (!isHideen) //文件夹 { DirectoryClass dc = new DirectoryClass(); dc.Name = dir.Name; dc.FullName = dir.FullName; dc.IsDirectory = true; dc.IsFixDriver = false; dc.CreateTime1 = dir.LastWriteTime.ToString("yyyy/MM/dd HH:mm"); ListViewItem item = new ListViewItem(); item.Text = dc.Name; item.Tag = dc; item.ImageIndex = _sysIcons.SmallImageList.Images.IndexOfKey("FileFolder"); item.SubItems.Add("文件夹"); item.SubItems.Add(dc.CreateTime1); item.SubItems.Add(""); _localListView.Items.Add(item); } #endregion } //循环添加文件 foreach (FileInfo file in dirs.GetFiles()) { #region 如果文件是只读的就不要读出来,不然会报错 string[] fileAttrites = File.GetAttributes(file.FullName).ToString().Split(','); //如果属性大于0的就说明有问题,只要属性里面有hidden就不要显示出来 bool isHideen = false; //是不是隐藏文件 foreach (string cAttrites in fileAttrites) { if (cAttrites.Equals("hidden", StringComparison.InvariantCultureIgnoreCase) || cAttrites.Equals("readonly", StringComparison.InvariantCultureIgnoreCase)) { isHideen = true; break; } } #endregion #region 如果isHideen==false就显示文件 if (!isHideen) { FileClass newFile = new FileClass(); newFile.Name = file.Name; newFile.FullName = file.FullName; newFile.FileExtends = file.Extension; //扩展名 newFile.CreateTime1 = file.LastWriteTime.ToString("yyyy/MM/dd HH:mm"); newFile.FileMax = Math.Round((file.Length / 1024.0 / 1024.0), 2); newFile.IsDirectory = false; //文件的扩展名称叫什么 string desc; IconHelper.GetExtsDescription(newFile.FileExtends, out desc); newFile.FileExtendsName = desc; ListViewItem item = new ListViewItem(); item.Text = newFile.Name; item.Tag = newFile; item.ImageIndex = _sysIcons.GetIconIndex(newFile.FullName, false); //子项 item.SubItems.Add(newFile.FileExtendsName); item.SubItems.Add(newFile.CreateTime1); double len = newFile.FileMax; if (len >= 1000) { len = Math.Round((len / 1024.0), 2); item.SubItems.Add(len + "GB"); } else { item.SubItems.Add(newFile.FileMax + "MB"); } _localListView.Items.Add(item); } #endregion } FillDirectoryHeader(); }); if (_localListView.InvokeRequired) { _localListView.Invoke(action); } else { action.Invoke(); } }