Search code examples
batch-filecmdscheduled-tasks

Keep the same file name on output file on a batch file


I'm currently working on an encrypting/decrypting automatization project and I need to create batch files for the task scheduler

And I'm facing the issue with the decrypting command

 --passphrase "password" --batch -d --output ".JOAARPT.out" "*.JOAARPT"

the command decrypts all the JOAARPT files and changes the output file to JOAARPT.out but I cannot make the created decrypted file keep the same name as the source file

What wildcard should I use?


Solution

  • In cmd.exe a FOR loop is needed. Yes, it is awkward, but it is what it is. Use the FOR /? command to learn all about it.

    FOR /F "delims=" %%A IN ('DIR /B "*.JOAARPT"') DO (
        decry.exe --passphrase "password" --batch -d --output "%%~nA.JOAARPT.out" "%%~A"
    )
    

    If you wanted to step up to PowerShell, you could:

    Get-ChildItem -File -Filter "*.JOAARPT" |
        ForEach-Object {
            & decry.exe --passphrase "password" --batch -d --output $($_.BaseName + '.JOAARPT.out') "$_.FullName"
        }