C
C#2y ago
00tree00

Delete only specific files

Hi everyone I would like the application to delete only the files that are in the array, I tried to do it this way but unfortunately it doesn't delete the files, maybe someone knows how to fix this?
string[] gamePaths = Directory.GetFiles(rootPath);


foreach (string gamePathss in gamePaths)
{
var name = new FileInfo(gamePathss).Name;
name = name.ToLower();
if (name == "d3dcompiler_43.dll" & name == "d3dx9_43.dll" & name == "glew32.dll" & name == "init.lua" & name == "libcrypto.dll" & name == "libcrypto-1_1.dll" & name == "libcurl.dll" & name == "libEGL.dll" & name == "libgcc_s_dw2-1.dll" & name == "libGLESv2.dll" & name == "libluajit.a" & name == "libssl-1_1.dll" & name == "libstdc++-6.dll" & name == "libwinpthread-1.dll" & name == "openal32.dll" & name == "otclientrc.dll" & name == "zlib.dll")
{
File.Delete(gamePathss);
}
}
string[] gamePaths = Directory.GetFiles(rootPath);


foreach (string gamePathss in gamePaths)
{
var name = new FileInfo(gamePathss).Name;
name = name.ToLower();
if (name == "d3dcompiler_43.dll" & name == "d3dx9_43.dll" & name == "glew32.dll" & name == "init.lua" & name == "libcrypto.dll" & name == "libcrypto-1_1.dll" & name == "libcurl.dll" & name == "libEGL.dll" & name == "libgcc_s_dw2-1.dll" & name == "libGLESv2.dll" & name == "libluajit.a" & name == "libssl-1_1.dll" & name == "libstdc++-6.dll" & name == "libwinpthread-1.dll" & name == "openal32.dll" & name == "otclientrc.dll" & name == "zlib.dll")
{
File.Delete(gamePathss);
}
}
4 Replies
lycian
lycian2y ago
Use or instead of and
00tree00
00tree00OP2y ago
Will this delete all the files in the folder or just the ones in the if?
lycian
lycian2y ago
just the ones in the if. Another way would be to just do:
string[] gamePaths = Directory.GetFiles(rootPath);
string[] filesToDelete = new string[] { "d3dcompiler_43.dll", "d3dx9_43.dll, ... }; // and so on

foreach (var gamePath in gamePaths)
{
var name = new FileInfo(gamePathss).Name;
if (filesToDelete.Contains(name.ToLower()))
{
File.Delete(gamePath);
}
}
string[] gamePaths = Directory.GetFiles(rootPath);
string[] filesToDelete = new string[] { "d3dcompiler_43.dll", "d3dx9_43.dll, ... }; // and so on

foreach (var gamePath in gamePaths)
{
var name = new FileInfo(gamePathss).Name;
if (filesToDelete.Contains(name.ToLower()))
{
File.Delete(gamePath);
}
}
00tree00
00tree00OP2y ago
it works! thanks a lot
Want results from more Discord servers?
Add your server