Answered by:
Search files lost sequence

Question
-
Hello friends,
In a folder on server Windows Server 2012, I have many files, they are sequential, type 00001ste.xlm, 00002ste.xlm, 00003ste.xlm, and so on.
Sometimes this sequence breaks, then there are missing files and I need to identify which ones of the sequence are missing and in the folder we have more than 1000 files.
Does anyone here know a power shell script to help me with this task?
I'm very grateful !
- Edited by Ivanildo Galvão Wednesday, September 12, 2018 11:33 AM
Wednesday, September 12, 2018 11:30 AM
Answers
-
Hi Ivanildo,
Thanks for your question.
About your question, you just want to get the missing file of the sequence. I think "Test-Path" cmdlet can help you to solve it. I hope you can get something from the example below.
$numbers = 1..1000 foreach ($number in $numbers) { $path = "filepath\0000$number`ste.xml" if (Test-Path $path) { # file exists } else { Write-Host "$path file does not exist" } }
May be you also need to verify the script for your need. I hope this can help you.
Best Regards,
Lee
Just do it.
- Marked as answer by Ivanildo Galvão Wednesday, September 26, 2018 11:25 AM
Thursday, September 13, 2018 3:11 AM
All replies
-
Hi Ivanildo,
Thanks for your question.
About your question, you just want to get the missing file of the sequence. I think "Test-Path" cmdlet can help you to solve it. I hope you can get something from the example below.
$numbers = 1..1000 foreach ($number in $numbers) { $path = "filepath\0000$number`ste.xml" if (Test-Path $path) { # file exists } else { Write-Host "$path file does not exist" } }
May be you also need to verify the script for your need. I hope this can help you.
Best Regards,
Lee
Just do it.
- Marked as answer by Ivanildo Galvão Wednesday, September 26, 2018 11:25 AM
Thursday, September 13, 2018 3:11 AM -
It worked, thank you very much for the help.
Ivanildo Teixeira Galvão
Wednesday, September 26, 2018 11:24 AM -
I think I'd modify one of the lines in your script, but that would depend on the format of the file names. If, for example, the file name must always 12 characters long then your script would work for the first 9 files but fail when the 10th file name was checked.
If the length of the file name must always be 12 characters then substituting this for your line of code would satisfy the requirement:
$path = "filepath\" + ("{0:D5}" -f $_) + "ste.xml"
--- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)
Wednesday, September 26, 2018 6:23 PM