Search code examples
file-iorenameautohotkeybatch-rename

Rename files without extension with AutoHotkey


I am trying to add .pdf to the filename of files without extension in a folder.

It is possible to rename for example txt files to pdf using the following command:

FileMove, %SourceFolder%\*.txt, %SourceFolder%\*.pdf

Also, I can add .pdf to all files by:

FileMove, %SourceFolder%\*, %SourceFolder%\*.pdf

But I only want to target only the files without extension. How to do this?


Solution

  • Example

    As suggested by kasper and MCL

    SetWorkingDir %A_ScriptDir%
    
    Loop, files\*
    {
        if !StrLen(A_LoopFileExt) ; if no file extension
        {
            FileMove,%A_LoopFileFullPath%,%A_LoopFileFullPath%.pdf ;rename file
        }
    }
    

    see [Loop, FilePattern]
    see [FileMove]