PDA

Click to See Complete Forum and Search --> : Excel 97 VBA - File Control


TheFIDDLER
Jul 20th, 2004, 05:27 PM
Question:

I am trying to delete several files from my system. This is code to be included with my program upgrade. We have several directories with pictures that are no longer used.

I can code to remove the files. I can code to delete the directories. This is done from within Excel 97 VBA.

I am getting errors due to the thumbs.dat file. Excel VBA does not seem to see this file in order to delete it. Consequently, I am left with an empty directory structure, each with their own thumbs.dat file.

Is there code that I am missing that would delete an entire directory including the thumbs.dat file that may reside in it.

Thanks

BrianB
Jul 21st, 2004, 03:03 AM
Cannot delete a folder until it is empty (use RmDir).
Kill "Mypath\*.*"
should delete all files in a folder.

TheFIDDLER
Jul 24th, 2004, 01:46 PM
should, but doesn't. thumds.db does not seem affected by this command.

It doesn't even come up with a DIR command.

And if I can't delete the file, then I can't delete the directory since it's not empty.

Dave Sell
Jul 25th, 2004, 10:22 AM
What OS is this? What program created all the thumbs.db files? The OS or some picture program. You might try looking at killing some kind of service.

TheFIDDLER
Jul 25th, 2004, 05:54 PM
thumbs.db is a system created file in windows XP.

I can delete it via the Windows Explorer or My Computer.

A DOS prompt, can't see it or delete it.
ANd I have yet to figure out how to get VBA to see it and delete it.

Dave Sell
Jul 25th, 2004, 06:14 PM
Try the ATTRIB command. I don't see any such file on my XP system, but I didnt look all over.

Use it like this:

ATTRIB *.* to show all the files from a command shell.

ATTRIB -s thumbs.db to remove the system property.

ATTRIB -h thumbs.db to remove the hidden attribute.

ATTRIB -r thumbs.db to remove the read-only attribute.

or,

ATTRIB -s -h -r thumbs.db to do it all at once. That may get you started in the right direction.

Dave Sell
Jul 25th, 2004, 06:15 PM
Oh ya, after all that you can delete the file :D

TheFIDDLER
Jul 25th, 2004, 09:05 PM
Tried this with no result.

dglienna
Jul 26th, 2004, 12:04 AM
it must NOT be opened to delete it

Dave Sell
Jul 26th, 2004, 07:11 AM
I agree there must be a program or service running that has the file(s) open.

I don't see that file on my other XP system either. Check for some graphical software running. Kill everything. Something has that file locked.

TheFIDDLER
Jul 26th, 2004, 05:46 PM
You're missing the point.

thumbs.db is a windows XP system created file.
IT's part of an Advanced Folder Setting: Do you want to cache thumbnails?
The file is self re-creating, meaning, it will replace itself each time a picture directory is opened within Windows XP. The file stores the thumbnail information for your user account and the directory you are looking at.

I am installing software on other people
s computer. I have no way of knowing if this file exists, but it is preventing me from deleting and changing my own directory structure. My software has two folders with graphics, so the user's computer, depending on the settings, may create this file for them.

I am not sure if there is any a process to kill. All I know is that I can see the file in Windows Explorer but not via code.

Are you sure it's not on you WIn XP system?
Click on my pictures, choose a folder with pics, and then under folder option, Show Protected Operating System Files.

Dave Sell
Jul 26th, 2004, 05:57 PM
Indeed you are correct, I found it under "My Pictures", but I was able to delete it via a command shell using ATTRIB and then DEL.

After that the file was gone.

I spose after the system reboots the file will return, but you should be able to delete the folder before that happens.

TheFIDDLER
Jul 26th, 2004, 08:06 PM
Can you do this via VBA?

Dave Sell
Jul 26th, 2004, 08:23 PM
I suppose with the Shell command you can do it. Need help with that?

TheFIDDLER
Jul 26th, 2004, 08:25 PM
Yep since I'm curious as to how different you code it from what I would do.

Ecniv
Jul 27th, 2004, 03:33 AM
Haven't tried this but:

public sub testforfile()

dim strFile as string, strPath as string

strPath="C:\testfolder"
strfile = dir$(strpath & "\*.*",63)
do until len(Strfile)=0
debug.print strfile
strfile=dir$
loop


I can't test here (win2k) but that 'should' return all the files/folders in the directory. Its the 63 bit that I always put in :)

Lemme know if it works or not :)

Vince

Dave Sell
Jul 27th, 2004, 07:14 AM
Originally posted by TheFIDDLER
Yep since I'm curious as to how different you code it from what I would do.


Shell "C:\Windows\system32\attrib -s -h -r ""C:\Documents and Settings\username\My Documents\My Pictures\thumbs.db"""
Shell "cmd.exe /c DEL ""C:\Documents and Settings\username\My Documents\My Pictures\thumbs.db"""