Hey friends,
I need help in order to write a VBA code much shorter and in a smart way.
I want to delete files located at specific folder, all the files except of pdf files.
The problem is that there are 8 extensions variations for the name "pdf" files
pdf, Pdf, PDf, pDF,pdF,PDF,pDf,PdF
In other words, for every file in the chosen folder the code make 8 checks:
I need help in order to write a VBA code much shorter and in a smart way.
I want to delete files located at specific folder, all the files except of pdf files.
The problem is that there are 8 extensions variations for the name "pdf" files
pdf, Pdf, PDf, pDF,pdF,PDF,pDf,PdF
In other words, for every file in the chosen folder the code make 8 checks:
VBA Code:
Sub Delete_Files_Not_Pdf()
' Enter file path to delete files from
myFolderName = "C:\Atricles\"
myFileName = Dir(myFolderName & "*.*")
' Delete all files without an pdf extension
Do While myFileName <> ""
If Right(myFileName, 3) <> "pdf" And Right(myFileName, 3) <> "Pdf" And Right(myFileName, 3) <> "PDf" And Right(myFileName, 3) <> "pDF" And Right(myFileName, 3) <> "pdF" And Right(myFileName, 3) <> "PDF" And Right(myFileName, 3) <> "pDf" And Right(myFileName, 3) <> "PdF" Then Kill myFolderName & myFileName
myFileName = Dir
Loop
End Sub