private void TxtPassWord_KeyPress(object sender, KeyPressEventArgs e) { hasCheckSel = true; if (e.KeyChar == 13) { tvMenu.Nodes.Clear(); if (!string.IsNullOrWhiteSpace(txtAddress.Text) && !string.IsNullOrWhiteSpace(txtUserName.Text) && !string.IsNullOrWhiteSpace(txtPassWord.Text)) { string ftpServerIp = txtAddress.Text.StartsWith("ftp://") ? txtAddress.Text.TrimEnd('/') : "ftp://" + txtAddress.Text.TrimEnd('/'); txtAddress.Text = ftpServerIp; FTPObj = new FtpHelper(); FTPObj.FtpUpDown(ftpServerIp, txtUserName.Text, txtPassWord.Text); var filesArr = FTPObj.GetFilesDetailList(); if (filesArr != null) { hasCheckSel = false; if (filesArr.Length == 0) { MessageBoxExtend("此路径无文件夹", MessageBoxIcon.Information); return; } List <TreeNode> treeNodes = new List <TreeNode>(); BuildTreeNode(filesArr, treeNodes, ftpServerIp); tvMenu.Nodes.AddRange(treeNodes.ToArray()); } else { MessageBoxExtend("连接失败!", MessageBoxIcon.Error); } } } }
private void btnQuery_Click(object sender, EventArgs e) { //通过时间筛选 //递归所有文件判断时间是否在这个区间 if (string.IsNullOrEmpty(txtSelectFolder.Text)) { MessageBox.Show("请选择要读取的文件夹!"); return; } if (string.IsNullOrEmpty(txtSaveFolder.Text)) { MessageBox.Show("请选择要保存的文件夹!"); return; } lblCount.Visible = false; lblSync.Visible = false; lblPoint.Visible = false; folderList = new LinkedList <string>(); dataGridView1.DataSource = null; lblLoading.Visible = true; DataTable dt = new DataTable(); dt.Columns.Add("OriginalPath", typeof(string)); dt.Columns.Add("SavePath", typeof(string)); dt.Columns.Add("FileName", typeof(string)); dt.Columns.Add("UpdateTime", typeof(string)); dt.Columns.Add("IsSync", typeof(bool)); Task.Factory.StartNew(() => { if (!cbFtpSel.Checked) { //改变列顺序 dt.Columns.Add("CreateTime", typeof(string)).SetOrdinal(4); #region 本地读取逻辑 DirectoryInfo di = new DirectoryInfo(txtSelectFolder.Text.Trim()); var dis = di.GetDirectories("*", SearchOption.AllDirectories); var fls = di.GetFiles("*", SearchOption.AllDirectories); string savePath = txtSaveFolder.Text.Replace("\\", "/") + "/"; foreach (var item in dis) { folderList.AddLast(savePath + item.FullName.Substring(txtSelectFolder.Text.Length + 1).Replace("\\", "/")); } foreach (var fl in fls) { DataRow dr = dt.NewRow(); dr["OriginalPath"] = fl.FullName; dr["SavePath"] = savePath + fl.FullName.ToString().Substring(txtSelectFolder.Text.Length + 1).Replace("\\", "/"); dr["FileName"] = fl.Name; dr["CreateTime"] = fl.CreationTime.ToString("yyyy-MM-dd HH:mm:ss"); dr["UpdateTime"] = fl.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss"); dr["IsSync"] = false; dt.Rows.Add(dr); } #endregion } else { #region FTP //ftpSel.ChangeServerIp(txtSelectFolder.Text); //获取父目录 string parentFolder = txtSelectFolder.Text; var filesArr = ftpSel.GetFilesDetailList(parentFolder); //if (!cbFtpSave.Checked) // if (txtSelectFolder.Text.IndexOf('/') != -1) // folderList.AddFirst(txtSelectFolder.Text); if (filesArr != null) { for (int i = 0; i < filesArr.Length; i++) { BuildData(filesArr[i], dt, parentFolder); } } #endregion } Invoke(new Action(delegate { DataGridBind(dt); lblLoading.Visible = false; })); }); }