• Code to delete filename suffixes

    Home » Forums » Developers, developers, developers » DevOps Lounge » Code to delete filename suffixes

    Author
    Topic
    #1774160

    I have a recurring situation in my WIP folder—where I pull in the bits for the current job. It happens due to the requirements of the processes feeding into and being fed by this WIP work. In one step I have 3 files like this:

    banana-ABC.pdf
    banana-ABC-123.txt
    banana-XYZ-123.txt

    I need to end up with:
    banana.pdf
    banana.txt
    banana-XYZ.txt

    So I manually edit the filenames & delete the ‘-ABC’ and ‘-123’ bits. Job done.
    Is there a code snippet which can do this?

    Notes:

    The ‘banana’ part changes with each job;
    The -ABC and -123 bits do not change, they are literally the same each job;
    The job is always done in the same folder;
    There are other files in the folder at this time;
    -ABC and -123 do not appear in any other files in the folder, they are unique to these 3 files.

    Lugh.
    ~
    Alienware Aurora R6; Win10 Home x64 1803; Office 365 x32
    i7-7700; GeForce GTX 1060; 16GB DDR4 2400; 1TB SSD, 256GB SSD, 4TB HD

    Reply To: Code to delete filename suffixes

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: