Powershell: move directory structure - if file exists compare the file modification date-time and append date-time to the name of the older file

81 views Asked by At

I need to move a whole directory structure over an existent directory structure which can be probably 90% similar. The files needed to be moved might have identical name correspondents in the directory target. It would be needed to be made a comparison of the same named files and to rename the one older with the date-name appended to the file name.

So: if source\dir1\file1 is older than target\dir1\file1 then rename source\dir1\file1 to source\dir1\file1_mod-date-time and move to target\dir1

Similarly: if source\dir1\file1 is newer than target\dir1\file1 then rename target\dir1\file1 to target\dir1\file1_mod-date-time and move source\dir1\file1 to target\dir1\

If there is no similar file in destination folder just move it there - and create a new sub-directory if not existent.

I am novice at Powershell and I tried pieces of this to make it work, but no success.

Any help would be VERY appreciated.

Thank you.

0

There are 0 answers