C# 2010 Check If Hidden File Exists
-
13 Nisan 2012 Cuma 18:08
Just that. I'm trying to make a backup on some databases, automatically set to hidden and squirreled away in a seldom-clicked folder.
Catch is, when they're set to hidden, System.IO.File.Exists doesn't notice it, and I haven't figured out how to merge
if ((at2 & FileAttributes.Hidden) == FileAttributes.Hidden) with Exists.
I just want it to come out like
if(hidden file exists) {overwrite}
else(if it doesn't) {//set error handling}
May the fleas of a thousand camels feast happily on the lower regions of your enemies. And may their arms be too short to scratch!
Tüm Yanıtlar
-
13 Nisan 2012 Cuma 18:23
Try this:
try
{
if( ( new FileInfo( path ).Attributes & FileAttributes.Hidden ) == FileAttributes.Hidden )
{
// file is hidden
}
else
{
// file is not hidden
}
}
catch( FileNotFoundException )
{
// file does not exist
}- Yanıt Olarak Öneren José Mendez 13 Nisan 2012 Cuma 18:27
- Yanıt Olarak İşaretleyen psifreak 13 Nisan 2012 Cuma 19:59
-
13 Nisan 2012 Cuma 19:59
Perfecto! Thanks much!
May the fleas of a thousand camels feast happily on the lower regions of your enemies. And may their arms be too short to scratch!
-
16 Nisan 2012 Pazartesi 05:25
HI,
Viorel thanks for the answer. This help me.
-
16 Nisan 2012 Pazartesi 11:53File.Exists should return true for an hidden file. However, it will return false if you're checking the existence of a folder. Use Directory.Exists to check a folder.