public static void create_user(string name, string pwd) { //先创建好文件及文件夹 string upath = ConstValue.userpath + name; Directory.CreateDirectory(upath); upath = upath + @"\" + name + ".user"; File.Create(upath).Close(); StreamWriter sw = new StreamWriter(upath); sw.Write("Name=" + name + "\n" + "PWD=" + pwd); sw.Flush(); sw.Close(); upath = ConstValue.userpath + name + @"\"; Directory.CreateDirectory(upath + @"file\home\usr"); string epath = ConstValue.envpath; File.Create(epath + name + ".env").Close(); string bpath = ConstValue.kernelpath + @"backup\"; File.Create(bpath + name + ".user.backup").Close(); sw = new StreamWriter(bpath + name + "user.backup"); sw.Write("Name=" + name + "\n" + "PWD=" + pwd); sw.Flush(); sw.Close(); User user = User.GetInstance(name); //更新索引表 IndexTableOperation.Update(user); }
/// <summary> /// 删除文件夹 /// </summary> /// <param name="u"></param> /// <param name="dname"></param> public static void deletedir(User u, string dname) { if (dname.StartsWith(@".\")) { dname = dname.Substring(2); } string tpath = TruepathParser.parse(u); try { Directory.Delete(tpath + @"\" + dname, true); } catch (Exception e) { Console.WriteLine("找不到该文件夹"); } //更新索引表 IndexTableOperation.Update(u); }
/// <summary> /// 删除文件 /// </summary> /// <param name="u"></param> /// <param name="fname"></param> public static void delete(User u, string fname) { if (fname.StartsWith(@".\")) { fname = fname.Substring(2); } string tpath = TruepathParser.parse(u); try { File.Delete(tpath + @"\" + fname); } catch (Exception e) { Console.WriteLine("找不到该文件"); } //更新索引表 IndexTableOperation.Update(u); }