Jump to content

Deleting files/ folders


Phillip
 Share

Recommended Posts

hey guys.

at the moment i have this script which should delete all folders in a particular directory.

DirRemove("C:\Documents and Settings\gabriel\Local Settings\Temp\*.tmp", 1)

this doesnt seem to work, however when i put *.* OR if i type the folder name manually it does work. Is there a reason why *.tmp wont work? this also applies to deleting files.

thank you.

Link to comment
Share on other sites

run("cmd.exe /c rmdir /Q /S somedir", "", @SW_HIDE)  ; Variant 1
FileDelete("somedir\*.tmp")                ;   if folder or directory has extension this help you.
run("cmd.exe /c del /q somedir\*.ext", "", @SW_HIDE)

Edited by Sh3llC043r
[size="5"] [/size]
Link to comment
Share on other sites

You could do a recursive file search on the folder. Then delete each file separately. There are good examples of recursive file searching on the forums. If you can get the command line working, it will be better, but I am not very good with command line operations.

Edited by dantay9
Link to comment
Share on other sites

You could do a recursive file search on the folder. Then delete each file separately. There are good examples of recursive file searching on the forums. If you can get the command line working, it will be better, but I am not very good with command line operations.

hmm i dont know its very wierd, like the script will work in some folders and delete all the files that have *.tmp

but with folders like: C:\documents and settings\*username*\local settings\temp it just wont delete the files i need deleted in there.

Link to comment
Share on other sites

but with folders like: C:\documents and settings\*username*\local settings\temp it just wont delete the files i need deleted in there

Maybe because cmd line utilities require quotes around paths with spaces in them ?

You then need to make sure the quotes don't get thrown out by AutoIt by switching to

single quotes to delimit your string, and re-adding the quotes, something like:

$path = "C:\documents and settings\username\local settings\temp"
run('cmd.exe /c rmdir /Q /S "' & $path & '"', "", @SW_HIDE)

hth,

whim

Link to comment
Share on other sites

Ok ive just discovered that when attempting to delete particular .tmp files, it gets stuck on files that are in use and cannot be deleted, therefor all the other files that are in line to be deleted, dont get deleted because it freezes on the file that Cannot be deleted due to it being in use.

Link to comment
Share on other sites

You need a way to check the files status, to see if it is locked down by a process. Simply you need something like DriveStatus for files but I don't know what it is. There is a SysInternals tool called ProcessExplorer that can tell you this information its just matter of getting that information into AutoIt so you can more the next one. That tool can release the lock but it is not advisable.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

You need a way to check the files status, to see if it is locked down by a process. Simply you need something like DriveStatus for files but I don't know what it is. There is a SysInternals tool called ProcessExplorer that can tell you this information its just matter of getting that information into AutoIt so you can more the next one. That tool can release the lock but it is not advisable.

drivestatus wont work and i dont really wanna use a tool that unlocks files in use, i just want to somehow skip the files that are being currently used and move on the to the next ones.

Link to comment
Share on other sites

drivestatus wont work and i dont really wanna use a tool that unlocks files in use, i just want to somehow skip the files that are being currently used and move on the to the next ones.

Yep. I had a look on MSDN but there is nothing I can see what will do what you want. I'm don't think a file knows if it has a look on it or not, I believe that is control 'else where'. Either way its involved, hopefully someone else will know the answer to check if a file is used by another process.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

mrbond007 posted a function that will do what you want.

Here: #370334

Thanks for the link Raven1. Reviewing mrbond007's and Valuater's code, at what point do they check to see if a process has a hold of a file? Either way mrbond007's function should do what is required.

@Phillip looking at the link I had a though, just check the return status of DeleteFile. If it returns 0 just move on anyway.

Edited by bo8ster

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

  • 2 weeks later...

@Phillip - came across a function thanks to KaFu. Checkout _FileInUse(). Does exactly what you need.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...