Being a beginner Being a beginner, I try to find a solution for application needs I create a daily symbolic link with the same naming convention.
Deletion of the last symbolic link type file at the destination
Creation of a symbolic type file at the destination by referring to the file that was created the same day at the source.
In this example the source file starts with the date and time followed by the file name "yyyy_MM_dd_HH_mm_ss_filereport.xls (2021_02_16_10_10_10_filereport.xls).
When the symbolic link is created, it is created without the start date (filereport.xls â.Symlinkâ)
The script below works correctly.
However, I canât do the same thing, when I have several daily files with different names but always starting with the date and time. Anyone have an idea how I can do the same on all the differently named log files?
I canât see how this script works at all. You potentially collect multiple files in the $file variable. Later you try to populate $DailyLog with a nonexistent variable $files (at least it doesnât exist in what youâve shown us.) Then the value of the symbolic link would be this empty $dailylog. You specify the -recurse option when gathering the .xls files so the path could be just $source or children. The destination is a single folder so you could potentially be putting all the reports into a single folder. This may be exactly what youâre after, but the $file vs $files and multiple source files (potentially, and likely based on your question) treated as a single are issues that you need to clarify for us.
Every day I receive logs but named differently and which always starts with the date and time (unfortunately I cannot parameter the logs differently because the naming of the source files cannot be changed in the system), example:
The source of the \ share \ report directory
2021_02_25_10_10_10_FilereportProduction.xls
2021_02_25_10_10_10_FilereportSharing.xsl
2021_02_25_10_10_10_FilereportEncryped.xls
2021_02_25_10_10_10_Filereport.xls
etc âŚ
So that an application can read these daily files I opted for a symlink creation solution updated every day with the source files of the day and always with the same name but without the date and time, I will want these symlink files are always named this way.
Destination of the \ share \ report \ Dayly directory
FilereportProduction.xls â.symlinkâ
FilereportSharing.xsl â.symlinkâ
FilereportEncryped.xls â.symlinkâ
Filereport.xls â.symlinkâ
etc âŚ
Unfortunately I am new to powershell, so my knowledge is quite basic. But I would like a script which is not based on fixed file names in a script but which will automatically take all the files that have arrived the day and create the symlinks at the destination keeping only the name which is after the date and hours. thank you in advance for your help
The file names are not a concern. What is a concern is if the files are all in the root of source or if they can be in subfolders. If they are all located right in source, great we just remove -recurse from the Get-ChildItem. If they are in sub folders then we need to account for the varying paths by using the full name property.
Hi
Thank you so much so much for your support, the script working very well,
Just a last question about the script, if the file is named FilereportProduction_2021_02_25_10_10_10.xls the $current = ($file.name -split â_â)[-1] is not available so what I have to change?
The script working very well with file named â2021_02_25_10_10_10_FilereportProduction.xlsâ, the symlinks created is : âFilereportProduction.xlsâ
But if the file is named like that âFilereportProduction_2021_02_25_10_10_10.xlsâ yes the symlinks is named â10.xlsâ
OK so when you split the file up by _ you end up with however many pieces. The last piece could be the 5th or the 10th or the 1000th so a convenient way to grab the last element is us -1 as we did before. To grab the first like in your new example, you can grab the 0 element. But then youâll need to add your file extension back.
⌠and to make the confusion complete ⌠of course there would be ways to pick the part of the filename not containing numbers regardless of its position.