Jump to content

Delete files with the same extension


 Share

Recommended Posts

I want to delete some files with the same extension from one folder.

I try this script but don't work

#Include <File.au3>
#Include <Array.au3>

$path = "D:\Notes"
$FileList = _FileListToArray($path, "*.txt")

For $i = 1 To $FileList[0]
    FileDelete($path & "\" & $FileList[$i])
Next

Code's clean and works fine for me - Except for "Read-Only" files. If that ends up being the case with your files, take a look at FileSetAttrib()

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Link to comment
Share on other sites

Sorry.

I found the problem. The script works, but in that folder I have other folders which include files.

The problem is to recurse in subdirectories.

Hi,

Use this UDF?;

; filedel.au3
#Include <FileListToArray.au3>
#Include <Array.au3>

$path = @ScriptDir

$FileList = _FileListToArray($path, "*.txt",1,1)
_arraydisplay($FileList)
;~ For $i = 1 To $FileList[0];~     FileDelete($path & "\" & $FileList[$i])
;~  ConsoleWrite($path & "\" & $FileList[$i]&@LF)
;~ Next
Link to comment
Share on other sites

@randallc you should avoid reposting attachments as often as possible. You should link directly to the main topic containing your scripts so there aren't a bunch of different versions floating around. This also prevents you from filling up your attachment space which I did a long time ago.

Link to comment
Share on other sites

Hi,

Use this UDF?;

; filedel.au3
#Include <FileListToArray.au3>
#Include <Array.au3>

$path = @ScriptDir

$FileList = _FileListToArray($path, "*.txt",1,1)
_arraydisplay($FileList)
;~ For $i = 1 To $FileList[0];~     FileDelete($path & "\" & $FileList[$i])
;~  ConsoleWrite($path & "\" & $FileList[$i]&@LF)
;~ NextoÝ÷ Ûú®¢×¶¸vØb±«­¢+Ø%¹±Õ±Ðí¥±1¥ÍÑQ½ÉÉä¹ÔÌÐì(%¹±Õ±ÐíÉÉä¹ÔÌÐì((ÀÌØíÁÑ ôMÉ¥ÁÑ¥È((ÀÌØí¥±1¥ÍÐô}¥±1¥ÍÑQ½ÉÉä ÀÌØíÁÑ °ÅÕ½Ð쨹ÑáÐÅÕ½Ðì°Ä°Ä¤)½ÈÀÌØí¤ôÄQ¼ÀÌØí¥±1¥ÍÑlÁt(%¥±±Ñ ÀÌØíÁÑ µÀìÅÕ½ÐìÀäÈìÅÕ½ÐìµÀìÀÌØí¥±1¥ÍÑlÀÌØí¥t¤)9á

with those 2 files provided, but nothing.

Link to comment
Share on other sites

Again I used this script

#Include <FileListToArray.au3>
#Include <Array.au3>

$path = @ScriptDir

$FileList = _FileListToArray($path, "*.txt",1,1)
_arraydisplay($FileList)
For $i = 1 To $FileList[0]
    FileDelete($path & "\" & $FileList[$i])
    ConsoleWrite($path & "\" & $FileList[$i]&@LF)
Next

and randallc's attachment files, but don't works.

Edited by dexter23
Link to comment
Share on other sites

Using this

; filedel.au3
#Include <FileListToArray.au3>
#Include <Array.au3>

$path = @ScriptDir

$FileList = _FileListToArray($path, "*.txt",1,1)
_arraydisplay($FileList)
For $i = 1 To $FileList[0]
    FileDelete($path & "\" & $FileList[$i])
    ConsoleWrite($path & "\" & $FileList[$i]&@LF)
Next

the files is founded and listed, but aren't deleted.

Link to comment
Share on other sites

with those 2 files provided, but nothing.

Hi,

Sorry; you don't need the path.

$FileList = _FileListToArray($path, "*.txt",1,1)
FileDelete($FileList[$i])oÝ÷ ÚÚºÚ"µÍÌÍÑ[SÝHÑ[SÝÐ^J   ÌÍÜ] ][ÝÊ  ][ÝËKK
B[Q[]J  ÌÍÜ] [È ][ÝÉÌLÉ][ÝÈ   [ÉÌÍÑ[SÝÉÌÍÚWJ

Just as well, though; you don't want to delete your scriptdirectory files?>...

Best, Randall

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...