点击Get List
按钮:
点击Create Folders
按钮
我想删除重复的扩展名并创建以ListBox中的项目命名的文件夹。
即创建名称为doc
,docx
,dwg
等的文件夹
private void btn_list_Click(object sender, EventArgs e)
{
listBox_ex.Items.Clear();
FolderBrowserDialog FBD = new FolderBrowserDialog();
if (FBD.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
lbl_path.Text = FBD.SelectedPath;
listBox_name.Items.Clear();
string[] filename = Directory.GetFiles(FBD.SelectedPath);
foreach (string file in filename)
{
listBox_name.Items.Add(Path.GetFileName(file));
listBox_ex.Items.Add(Path.GetExtension(file).Replace(".", ""));
}
}
}
private void btn_CreateFolder_Click(object sender, EventArgs e)
{
FolderBrowserDialog FBD2 = new FolderBrowserDialog();
if (FBD2.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
lbl_pathCreated.Text = FBD2.SelectedPath;
}
string path = lbl_pathCreated.Text;
if (!Directory.Exists(path)) {
Directory.CreateDirectory(path);
} else {
MessageBox.Show("already exit");
}
}
答案 0 :(得分:1)
替代方法,使用2个 import requests
urls = ['https://www.khanacademy.org/api/internal/user/kaid_329989584305166460858587/profile/widgets?lang=en&_=190424-1429-bcf153233dc9_1556201931959',
'https://www.khanacademy.org/api/internal/user/kaid_901866966302088310331512/profile/widgets?lang=en&_=190424-1429-bcf153233dc9_1556201931959']
for url in urls:
r = requests.get(url).json()
result = [item['renderData']['discussionData']['statistics']['votes'] for item in r if 'votes' in str(item)]
print(result)
对象将当前文件的选择和文件扩展名存储为Distinct,Ordered元素。
然后将列表用作ListBox.DataSource。
更改数据源时,将重置List<string>
收集器。
选择目标路径后,扩展列表中的每个项目都将用于在所选路径中创建目录。
无需检查目录是否已经存在:Directory.CreateDirectory()只是忽略它。
您可能要为用户选择的路径添加验证过程。用户可能选择了奇怪的目的地。
ListBox.Items