Forum Discussion

_ivanovich_'s avatar
_ivanovich_
Frequent Contributor
4 years ago

How to get filename with path after renaming it with groovy?

Hi,

with groovy i can rename a file with:

def filex = new File("C:\\temp\\test.txt").renameTo(new File("C:\\temp\\test"+(sdf.format(date))+".txt"))

now i want to know the file name newly renamed.

I tried this:

log.info filex

it returns true

 

i tried

log.info filesx.toString()

it returns true

 

The goal is to set custom property with the path and the the name of the newly renamed file.

like: C:\\temp\\test-03-12-2021_08_48_20.txt

 

Thank you for having a look

 

 

 

 

  • ZDGN's avatar
    ZDGN
    4 years ago

    Hi _ivanovich_ 

     

    In case you still want to know, the command you were looking for is:

     

    log.info filex.getName()

     

    I use to concatenate path, current date, file name and extension to get the full path.
    So I can retreive any fo those information ğŸ˜‰

     

    Have a nice day.

     

    David.

  • _ivanovich_'s avatar
    _ivanovich_
    Frequent Contributor

    Problem resolved by setting property dynamically a value with renaming process.

    • ZDGN's avatar
      ZDGN
      Contributor

      Hi _ivanovich_ 

       

      In case you still want to know, the command you were looking for is:

       

      log.info filex.getName()

       

      I use to concatenate path, current date, file name and extension to get the full path.
      So I can retreive any fo those information ğŸ˜‰

       

      Have a nice day.

       

      David.