Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete DBF Files inside folder

Status
Not open for further replies.

TheLazyPig

Programmer
Sep 26, 2019
103
PH
Hi!

How can I delete all files inside a basket folder without deleting the folder itself?

It can also have sub-folders inside the basket folder.

I tried to use ERASE or DELETE FILE but nothing happens.

Code:
pcScrPath = pcCurrDir+"\basket\"

ERASE pcScrPath+"*.dbf"


Thank you in advance! :)
 
First thing to do: Put pcScrPath+"*.dbf" in parantheses:

[tt]ERASE [highlight #FCE94F]([/highlight]pcScrPath+"*.dbf"[highlight #FCE94F])[/highlight][/tt]

A couple of other things to check:

- Make sure the DBFs are not open when you execute this command.

- Are the DBFs part of a database (a DBC)? If so, you should first remove them from the database, using REMOVE TABLE.

- Check that pcScrPath+"*.dbf" actually contains what you expect it to contain. There might for example be a spurious backslash in there (in general, it's better to use FORCEPATH() when constructing path/filenames like this).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
TLP,

Here's a cursor I create to list all subfolders under a folder. It can be SCANned to list all files in each folder so you can delete (or do anything else) with each of the files.

Code:
CREATE CURSOR Folders (FolderName C(200))
pcScrPath = pcCurrDir+"\basket\"
INSERT INTO Folders VALUES (m.pcScrPath)
nextRec = 1
DO WHILE m.nextRec <= RECCOUNT()
 GOTO m.nextRec
 srcFolder = ADDBS(ALLTRIM(FolderName))  && Includes drive letter
 FOR ii = 3 TO ADIR(aFolder,m.srcFolder+'*','D')  && Subfolders. Skip . & ..
  IF 'D' $ aFolder(m.ii,5)
   INSERT INTO Folders VALUES (ADDBS(m.srcFolder+aFolder(m.ii,1)))  && SubFolder name - On source
  ENDIF
 ENDFOR
 nextRec = m.nextRec + 1 
ENDDO

SCAN
 folder = ADDBS(ALLTRIM(FolderName))
 FOR ii = 1 TO ADIR(aFile,m.folder+'*')
  ERASE (m.folder+aFile(m.ii,1))
 ENDFOR
ENDSCAN

HTH

Steve
 
Mike said:
ERASE (pcScrPath+"*.dbf")
works but only if the basket folder doesn't have sub-folders.

- I tried to used REMOVE TABLE because I was getting an error of "File In Use" but got an error of not a DATABASE Table so I removed it.

- I then replaced it to CLOSE TABLE above the ERASE and the error did not appear again

- pcCurrDir = CURDIR(), I wanted to look what directory the ?CURDIR() is but it was different from where I was testing my program. Then I looked at TOOLS > OPTIONS > FILE LOCATIONS > DEFAULT DIRECTORY in foxpro and the path there is what the ?CURDIR() is. So I had to change it. But when I compiled it to .exe and move it to another testing folder it seems fine.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top