我有一个包含 .jpg 文件的文件夹。我将这些与访问数据库中的产品相关联。产品来源之一提供了这些 .jpg 文件,但它们不允许您仅轻松下载当前使用的图片。因此,我找到了一个 PowerShell 脚本来删除我不需要的文件。
$exclusions = Get-Content C:\Users\office\Desktop\ExcludedPhotos.txt
dir -rec M:\PhotoDirectory\PhotoFolder | Where-Object {$exclusions -notcontains $_.name } | Remove-Item
Run Code Online (Sandbox Code Playgroud)
归功于@x0n Powershell 脚本,用于删除列表中未指定的文件
而且效果很好!但问题是它需要永远,我有超过 180,000 项要搜索和删除。所以我想做一个进度条,让我知道我已经完成了多少过程。
所以经过一番搜索,我找到了一篇名为“使用进度条”的文章
问题是我不知道如何将两者混合在一起,但是我在这里尝试过:
$exclusions = Get-Content C:\Users\office\Desktop\ExcludedPhotos.txt
1..100 | foreach-object {
Write-Progress -Activity "Deleting Files" -Status "$_ %" -Id 1 -PercentComplete $_ -CurrentOperation "Deleting File $_"
dir -rec M:\PhotoDirectory\PhotoFolder | Where-Object {$exclusions -notcontains $_.name } | Remove-Item
}
Run Code Online (Sandbox Code Playgroud)
然而,这似乎比原始脚本花费的时间更长,我不知道它是如何工作的,当我只需要删除 10-15 个文件时,我正在测试它。
很可能我缺少一些非常基本的东西,但我真的很感激能帮助理解这一点。
在这里,我添加了一个屏幕截图:
我目前正在卸载一些为大量文件生成数据的软件,.jpg并且.nfo我想删除这些文件。我正在尝试使用 PowerShell 来执行此操作,我尝试过的命令是:
del /S *.jpg
Run Code Online (Sandbox Code Playgroud)
并收到以下结果:
删除项目:找不到接受参数“*.jpg”的位置参数。
在行:1个字符:1
+ del /S *.jpg
+ ~~~~~~~~~~~~
+ CategoryInfo:InvalidArgument:(:) [Remove-Item],ParameterBindingException
+ ExcellentQualifiedErrorId:PositionalParameterNotFound,Microsoft.PowerShell .Commands.RemoveItemCommand
谢谢!
我有一个包含子目录的目录,我想从中删除名称包含out. 这样做的最快方法是什么?
我已经尝试了几件事。
一个简单的:
rm */*out*
Run Code Online (Sandbox Code Playgroud)
珀尔:
perl -e 'for ( <*/*out*> ) { ( (stat)[9] < (unlink) ) }'
Run Code Online (Sandbox Code Playgroud)
每一个似乎都需要花费大量的时间。对于 1,000 个子目录,每个子目录包含大约 50 个匹配的文件*out*,需要:
Perl: ~25 mins
rm */*out* : ~18 mins
Run Code Online (Sandbox Code Playgroud)
我也尝试过rsync,先将文件移动到一个文件夹,然后与删除同步,但这需要很长时间。
有没有人有更快的方法来摆脱这些文件,因为这对我来说似乎非常慢?
我有一个大约 11M 关系的巨大文件。当我运行查询时:Match (n) detach delete n,似乎要花很长时间才能完成。我做了一些研究,发现我需要删除具有限制的关系,然后使用该查询删除节点:
MATCH (n)
OPTIONAL MATCH (n)-[r]-()
WITH r LIMIT 200000
DELETE r
RETURN count(r) as deletedCount
Run Code Online (Sandbox Code Playgroud)
然而,当我在做一些性能比较时,对我来说将删除孔图的总删除时间相加似乎不合逻辑。并且在更改要立即删除的关系的限制值时会发生变化。(如果我做 2000 个关系,它与一次 20000 个关系不同)
我该如何解决这个问题?任何帮助,将不胜感激
我想使用 curl 删除文件
我正在使用 SFTP,下面是我正在使用的代码。它不适合我
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_URL, "sftp://use:@101.101.101.101/");
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
curl_setopt($ch, CURLOPT_PORT, 51402);
curl_setopt($ch, CURLOPT_SSH_PRIVATE_KEYFILE, '/home/web/.ssh/id_rsa');
curl_setopt($ch, CURLOPT_SSH_PUBLIC_KEYFILE, '/home/web/.ssh/id_rsa.pub');
curl_setopt($ch, CURLOPT_SSH_AUTH_TYPES, CURLSSH_AUTH_PUBLICKEY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_QUOTE, array("DELE /dispatch/confirm/W00027478.csv"));
$result = curl_exec($ch);
$error_no = curl_errno($ch);
curl_close($ch);
if ($error_no == 0) {
echo "Delete File $filename<br>";
} else {
echo "File Not Delete $filename<br>";
}
Run Code Online (Sandbox Code Playgroud) 我需要删除临时文件夹中的所有内容。我知道我可以使用filesystem::remove_all,filesystem::remove_all_dir但这意味着程序也会删除临时文件夹本身,这当然不是我想要的。我找不到 C++ 的答案,所以如果你们能帮忙,那就太好了。
谢谢!
我正在寻找一种方法,如何使用Python清除文件夹中的文件,除了最后五个项目。
我对 Python 很陌生,所以我只能用max()函数保留最后一个文件,但我不知道如何保留最后 5 个文件。
有人有类似的问题吗?
谢谢你的任何想法。
我有几个文本文件,名为:
temp1.txt
temp2.txt
temp3.txt
temp4.txt
track.txt
Run Code Online (Sandbox Code Playgroud)
我只想删除以 开头temp和结尾的文件.txt。我尝试使用os.remove("temp*.txt")但出现错误:
The filename, directory name, or volume label syntax is incorrect: 'temp*.txt'
Run Code Online (Sandbox Code Playgroud)
使用 python 3.7 执行此操作的正确方法是什么?
我遇到了一些我在C#中编写的代码问题.
我正在使用MailMessage和SMTP组件发送文档.我将要发送的文件复制到临时目录(例如c:\ temp),遍历文档并将它们附加到电子邮件中.
电子邮件发送正常,但是当我尝试从临时目录中删除文件时,我收到以下错误:
该进程无法访问该文件,因为该文件正由另一个进程使用
我不明白为什么会这样.下面是处理文档的代码
public void sendDocument(String email, string barcode, int requestid)
{
string tempDir = @"c:\temp";
//first we get the document information from the database.
Database db = new Database(dbServer, dbName, dbUser, dbPwd);
List<Document> documents = db.getDocumentByID(barcode);
int count = 0;
foreach (Document doc in documents)
{
string tempPath = tempDir + "\\" + doc.getBarcode() + ".pdf";
string sourcePath = doc.getMachineName() + "\\" + doc.getFilePath() + "\\" + doc.getFileName();
//we now copy the file from the source …Run Code Online (Sandbox Code Playgroud) 今天我正在乱搞java.io.File方法,偶然发现了一些奇怪的东西.
当我重命名目录时,我似乎无法删除文件或新目录.
File dir = new File("dir");
dir.mkdir();
File file = new File(dir, "afile.txt");
file.createNewFile();
File newname = new File(dir, "newName.txt");
file.renameTo(newname);
File newdir = new File("newdir");
dir.renameTo(newdir);
System.out.println("file exists? " + file.exists());
System.out.println("file deleted? " + file.delete());
System.out.println("newname exists? " + newname.exists());
System.out.println("deleted newname? " + newname.delete());
System.out.println("dir exists? " + dir.exists());
System.out.println("dir deleted? " + dir.delete());
System.out.println("newdir exists? " + newdir.exists());
System.out.println("deleted newdir? " + newdir.delete());
Run Code Online (Sandbox Code Playgroud)
产量输出:
file exists? false
file deleted? false
newname exists? false
deleted newname? …Run Code Online (Sandbox Code Playgroud) delete-file ×10
file ×3
powershell ×2
python ×2
windows ×2
bash ×1
c# ×1
c++ ×1
curl ×1
email ×1
file-rename ×1
java ×1
linux ×1
neo4j ×1
performance ×1
perl ×1
php ×1
progress-bar ×1
sftp ×1
shell ×1
time ×1
winapi ×1