EldoS | Feel safer!

Software components for data protection, secure storage and transfer

How do i delete a directory that is not empty?

Also by EldoS: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.
#29186
Posted: 04/09/2014 06:08:43
by Peter Flynn (Basic support level)
Joined: 03/04/2014
Posts: 10

Hi

I am evaluating Solfs for us in a project we are running.

As part of this we download a zip file to the storage file and then extract it to a unique directory.

I can then delete the zip file from the storage.

However we wish to have the ability to delete this folder?

The DeleteFolder function requires the folder to be empty?

Does this mean that I need to go through the folder and subfolders and delete each file within this individually?

If so can you provide me with an sample of how to do this as I would have thought that this functionality would indeed be there?

Regards

Peter
#29187
Posted: 04/09/2014 06:13:51
by Eugene Mayevski (EldoS Corp.)

Yes, you need to traverse the directory and delete files recursively.

You need to use FindFirst and FindNext methods as you would do with Win32 API.


Sincerely yours
Eugene Mayevski
#29189
Posted: 04/09/2014 07:25:54
by Peter Flynn (Basic support level)
Joined: 03/04/2014
Posts: 10

Hi Eugene

Thanks. Is there any samples of this in action as I am sure it has been requested before?

Regards

Peter
#29191
Posted: 04/09/2014 07:36:45
by Eugene Mayevski (EldoS Corp.)

No, this has never been requested before and there are no samples available. If you do google search for "sample code to delete directory recursively windows" you will find plenty of samples for C or Delphi (those samples would use Windows Find*** functions but they have direct analogs in SolFSStorage class). With .NET or Java the situation is a bit more complicated because they use wrapper classes for filesystem manipulation, and we don't have APIs that mimic those classes).


Sincerely yours
Eugene Mayevski
#29192
Posted: 04/09/2014 07:41:59
by Eugene Mayevski (EldoS Corp.)

Pseudocode for recursive file deletion would be

Code
function DeleteDirectoryRecursively(string path)
{
  // cleanup subdirectories
  if SolFSStorage.FindFirst(SearchObj, path + "\*.*", attrDirectory)
  {
    do (
      DeleteDirectoryRecursively(path + SearchObj.FileName);
    ) while (SolFSStorage.FindNext(SearchObj));

    SolFSStorage.FindClose(SearchObj);
  }

  if SolFSStorage.FindFirst(SearchObj, path + "\*.*", attrAnyFile & !attrDirectory)
  {
    do (
      SolFSStorage.DeleteFile(path + SearchObj.FileName);
    ) while (SolFSStorage.FindNext(SearchObj));

    SolFSStorage.FindClose(SearchObj);
  }
}


Sincerely yours
Eugene Mayevski
#29197
Posted: 04/09/2014 08:09:15
by Peter Flynn (Basic support level)
Joined: 03/04/2014
Posts: 10

One more Quick question

What should the filemask (SearchObj) be for a search to get all files?

Peter
#29198
Posted: 04/09/2014 08:14:54
by Eugene Mayevski (EldoS Corp.)

SearchObj is not a mask but an object which contains search results. The mask is in "path + "\*.*" part (second parameter). Please refer to the help for details.


Sincerely yours
Eugene Mayevski
#29199
Posted: 04/09/2014 08:29:42
by Peter Flynn (Basic support level)
Joined: 03/04/2014
Posts: 10

Thanks :(

I'll figure it out so myself

Peter
Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.

Reply

Statistics

Topic viewed 3384 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!