1,105,333 Community Members

How to Force Folder Delete if it contains Files?

Member Avatar
Bile
Junior Poster in Training
96 posts since Dec 2010
Reputation Points: 10 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

-->>Hi, here is athing I managed to write Codes that Creates a Folder for a User when Registered...
-->>The Folder takes User's registered name with some additional files inside it,works very fine...
-->>The code I used is this one:

MkDir GetAppPath() & "SPGPAC - File User Files\" & UCase(txtUserName.Text)
MkDir GetAppPath() & "SPGPAC - File User Files\" & UCase(txtUserName.Text) & "\SPGPAC - File Music"
MkDir GetAppPath() & "SPGPAC - File User Files\" & UCase(txtUserName.Text) & "\SPGPAC - File Notices"
MkDir GetAppPath() & "SPGPAC - File User Files\" & UCase(txtUserName.Text) & "\SPGPAC - File Pictures"
MkDir GetAppPath() & "SPGPAC - File User Files\" & UCase(txtUserName.Text) & "\SPGPAC - File Videos"
MsgBox "User Name: " & txtUserName.Text & " Registered Successful.", vbOKOnly + vbInformation, "Registration Completed."

-->>Now the Problem is when the User Account is Closed (Deleted) I need His/Her Parent Folder to be Deleted...
-->>But what happens is the Folder wont delete if there are some Sub Folders or Files in it...
-->>And I get "Access denied" Error the Code I used to Delete the Parent Folder is:

RmDir GetAppPath() & "\SPGPAC - File User Files\" & USER_NAME

-->>Once I delete all Sub Folders with the same line of code I get rid of It!!!
-->>So I was wondering how can I force it Out without considering Sub Folders or Files?...
-->>And an Interesting Point to Me is the Error "Access denied" if there is a Way I can Make the Folders...
-->>Inaccessible outside the Appl I hope it 'll be usefull so that Only Access is granted upon User Login...
-->>in an Application (That is Not accessible by navigating to the Location it resides and just Click to open)
-->>That's all,any help?...

Member Avatar
rishif2
Posting Whiz in Training
284 posts since Dec 2012
Reputation Points: 57 [?]
Q&As Helped to Solve: 58 [?]
Skill Endorsements: 4 [?]
 
1
 

try this

Dim fso As New FileSystemObject
fso.DeleteFolder GetAppPath() & "\SPGPAC - File User Files\" & USER_NAME 

before putting this code first add references and so goto project menu and then select references option and then select Microsoft Scripting Runtime

hope this helps you

Member Avatar
Bile
Junior Poster in Training
96 posts since Dec 2010
Reputation Points: 10 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

-->>That realy helped Me alot and NOW I'm happy...
-->>Thanks rishif2...

Member Avatar
Bile
Junior Poster in Training
96 posts since Dec 2010
Reputation Points: 10 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

-->>WOW!! Sorry almost Forgot what about:

-->>Is there a Way I can Make the FoldersInaccessible outside the Appl I hope it 'll be usefull so that Only Access is granted upon User Login...
-->>in an Application (That is Not accessible by navigating to the Location it resides and just Click to open)

Member Avatar
AndreRet
Industrious Poster
4,492 posts since Jan 2008
Reputation Points: 362 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 24 [?]
 
0
 

I actually had the same scenario a while ago. There is no real solution to your problem because of admin right and non-admin right users. There is some software that you can use to protect a folder but that will mean that you have to run 3rd party apps to get what you want.

Don't know if anyone else here might have a solution to this. I have searched for quite some time and abondoned the entire idea. I moved over to MySql and started running my apps from a server with the databases residing there where all necessary security was in place...

Member Avatar
Bile
Junior Poster in Training
96 posts since Dec 2010
Reputation Points: 10 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

-->>Thank You AndreRet,I also have decided to Move on and I was passing through the...
-->>Inno Setup Compiler Software Version 5.5.1 Inno Setup
-->>This documentation Explains some how on treating Application Files/Folder...
-->>I think it 'll lead Me some how,I'll let You know once I made it...
-->>Thanks...

Member Avatar
AndreRet
Industrious Poster
4,492 posts since Jan 2008
Reputation Points: 362 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 24 [?]
 
0
 

Only a pleasure as usual. When done, don't forget to mark it as answered, thanx. :)

Question Answered as of 1 Year Ago by AndreRet and rishif2
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article