hi all
I want to write a visual C# programs that delete all files and folders in specific directory but leave the parents directory like
temp file
C:\Users\user\AppData\Local\Temp
MSN cache
C:\Users\user\AppData\Local\Microsoft\Windows Live\Contacts
etc etc...
but I need some help I had read the msdn library
http://msdn.microsoft.com/en-us/library/fxeahc5f.aspx
anyone could help me to write a program like that ?
xXghostXx
0
Junior Poster in Training
Recommended Answers
Jump to PostTry this link. This one deals with working with files. Use this info to delete the files in the directory you want to keep. Use the other info you got to delete any subdirectories and their files in that directory.
Jump to PostForEach will work. use directory.getfiles to load an array with the fullpaths of all the files in a directory. then pass each string to files.delete
Jump to PostI looked at the documentation for 'directoryinfo' and it indicates that your code will delete only the directories. I've put together a small routine that will do what you asked:
private void DeleteContents(string Path) { string[] DirectoryList = Directory.GetDirectories(Path); string[] FileList = Directory.GetFiles(Path); foreach (string Fil …
Jump to PostHere's a try-catch block you can try if you want:
try { } catch(Exception e) { if (e.Message.Contains("NotFound")) { } else throw (e); }
This will ignore anything notfound and thorw anything(i.e. no permission)
Jump to PostFinfo can only be read. You cannot set it's Length property. I guess you mean to do this:
public int File_Size() { int TotalFileSize = 0; DirectoryInfo X = new DirectoryInfo("C:\\Users\\Samer\\Desktop\\1"); FileInfo[] FileSize = X.GetFiles(); foreach (FileInfo Finfo in FileSize) { TotalFileSize += Finfo.Length; } return …
All 29 Replies
tinstaafl
1,176
Posting Maven
xXghostXx
0
Junior Poster in Training
xXghostXx
0
Junior Poster in Training
tinstaafl
1,176
Posting Maven
xXghostXx
0
Junior Poster in Training
xXghostXx
0
Junior Poster in Training
tinstaafl
1,176
Posting Maven
tinstaafl
1,176
Posting Maven
xXghostXx
0
Junior Poster in Training
xXghostXx
0
Junior Poster in Training
pritaeas
2,194
¯\_(ツ)_/¯
Moderator
Featured Poster
tinstaafl
1,176
Posting Maven
xXghostXx
0
Junior Poster in Training
tinstaafl
1,176
Posting Maven
xXghostXx
0
Junior Poster in Training
tinstaafl
1,176
Posting Maven
xXghostXx
0
Junior Poster in Training
tinstaafl
1,176
Posting Maven
tinstaafl
1,176
Posting Maven
xXghostXx
0
Junior Poster in Training
tinstaafl
1,176
Posting Maven
xXghostXx
0
Junior Poster in Training
tinstaafl
1,176
Posting Maven
xXghostXx
0
Junior Poster in Training
tinstaafl
1,176
Posting Maven
xXghostXx
0
Junior Poster in Training
tinstaafl
1,176
Posting Maven
xXghostXx
0
Junior Poster in Training
tinstaafl
1,176
Posting Maven
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.