From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 5179D1A1E30 for ; Wed, 12 Oct 2016 07:31:56 -0700 (PDT) Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D7315635F3; Wed, 12 Oct 2016 14:31:55 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-92.phx2.redhat.com [10.3.116.92]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9CEVsUU016520; Wed, 12 Oct 2016 10:31:55 -0400 To: GN Keshava References: From: Laszlo Ersek Cc: edk2-devel-01 Message-ID: Date: Wed, 12 Oct 2016 16:31:54 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 12 Oct 2016 14:31:55 +0000 (UTC) Subject: Re: Format a volume in UEFI (or delete all files) X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Oct 2016 14:31:56 -0000 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit On 10/12/16 12:48, GN Keshava wrote: > Hi all, > > I need to format fs1: (or delete all files and folders in root directory) > from my UEFI application. > > I'm able to use file system APIs such as Open, Write or Delete too. But > Delete API needs File (file path) as argument, but what I want is delete > all files (irrespective of file name). > > What could be the best method? Is there any API to directly delete all > files? If not, How to go through (Open) all files and delete each? > > How I can get each file and folder names in a directory programmatically ? Implement recursive directory traversal. (Minimally) the CP, LS, and TOUCH commands support the "-r" option, for recursive operation. I guess you could consult their implementations, if you don't want to implement the traversal from scratch. ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c ShellPkg/Library/UefiShellLevel3CommandsLib/Touch.c Actually... the RM command supports recursive file & directory removal without additional options. The UEFI shell spec 2.2 (Jan 26, 2016) says under RM: This command deletes one or more files or directories. If the target is a directory, it will delete the directory, including all its subdirectories. [...] So I guess you could copy & customize the code from ShellPkg/Library/UefiShellLevel2CommandsLib/Rm.c The CascadeDelete() function looks relevant: "Delete a node and all nodes under it (including sub directories)". Thanks Laszlo