Solved

Can't delete files in both root and folder, just one of them

Posted on 1999-01-09
1
142 Views
Last Modified: 2010-05-03
I have a problem with file deletion. It's on this row 8. When the "\" is there I can delete files in any folder, but not in the root. (C:\\). If I remove the "\" I can delete files in the root directory, but then it doesn't work to delete files in folders. Can anyone help me to solve how to delete files in folders and in the root directory at the same time?

Here are the codes I use:

1. Dim r As Long
2. Dim file2Delete As String
3. Dim fPath As String
4. Dim ActionFlag As Long

5. fPath = Dir1.Path
6. file2Delete = File1.filename

7. file2Delete = File1.List(File1.ListIndex)
8. file2Delete = fPath & "\" & file2Delete

9. ActionFlag = 0&
10. If optDeleteOption(0).Value Then ActionFlag = FOF_ALLOWUNDO

11. ShellDeleteOne file2Delete, ActionFlag

It will mean a lot to me if anyone solve this.
0
Comment
Question by:Ecmil
1 Comment
 

Accepted Solution

by:
halsch earned 100 total points
ID: 1455059
Between lines 5 and 6 add:
If Right(fPath,1)="\" then fPath = Left(fPath, Len(fPath)-1))

This will assure that the Directory does NOT end with a "\".  You can then concatenate a "\" without problems in line 8.

The conditional code will be executed only in the root directory.

Alternatively, you can remove the '& "\"' from line 8 and after line 5, add:
If Right(fPath,1)<>"\" then fPath = fPath & "\"

Either way should work.

Good Luck!
Hal
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VB6 convert MSHFlexgrid1 cells no2 2 50
DO Loop not working 4 63
vba find the last empty column 10 81
Problem to skip loop 6 49
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now