Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Reading a file archive going backwards...

Reply
 
Old 06-18-2009   #1 (permalink)
TimParker


 
 

Reading a file archive going backwards...

I am looking for a bit of help. I have a couple of remote
transcriptionists and I have a report for all our transcriptionists
that reports on the total number of dictations that they have
currently assigned to them. This report is still wrong a lot of times,
based on whether or not these two are connected and a have a current
file from them.

I have the following that I am doing:

$user7 = "User Name"
$filepath7 = "\\wkstn0020\newsletter\DictationCounts_KP.txt"

$testUser = Test-Path $filepath7
if($testUser -eq $TRUE){
[INT]$count7 = (gc $filepath7)
}
elseif ($testUser -eq $FALSE){
[INT]$count7 = 0
}

At the end of the job I clean up these files. Adding the Date to the
files 20090618-

#Cleanup/Rename two temp files for Kathy and Christina
$rendate = (get-date)
$rendate=$rendate.tostring("yyyyMMdd")
Rename-Item \\wkstn0020\newsletter\DictationCounts_KP.txt $rendate-
DictationCounts_KP.txt

I would like to change the false portion above to start reading
backwards from the previous day, if it finds a file then use that
count instead of the zero. I am starting to confuse myself as I am
thinking too hard about this I think. If for some reason (weekend,
vacation, days off) it could be several days back before I would have
a file, which would be about as accurate as I can get.

Thanks for any help.

Tim

My System SpecsSystem Spec
Old 06-19-2009   #2 (permalink)
Alex K. Angelopoulos


 
 

Re: Reading a file archive going backwards...

I don't think I know all the requirements you seem to have, but here's the
approach I think you want to take. Note that I'm ignoring what you say about
errors since I'm not clear whether you mean errors thrown by your script,
functional errors you believe are caused by the script, or something else.
I'm also unclear about the renaming operation details. Here's what I'm
assuming your requirements are and then a solution.

requirements: You want to get the content of the most recent dictation
counts file. When created the file is named DictationCounts_KP.txt. If that
file exists, you'll read it and then change it's name to
yyyymmdd-DictationCounts_KP.txt. If the file does not exist, you want the
most recent dictationcounts file. From what I can see, this implies that
you're OK with renaming the file as soon as you see it.

I would simply do this:

$sharepath ="\\wkstn0020\newsletter"
$filename = "DictationCounts_KP.txt"
#Start out by renaming the new dictationscount file if it exists
if(test-path $sharepath\$filename){
$today =(Get-Date).ToString("yyyyMMdd")
Rename-Item $sharepath\$filename $sharepath\$today-$filename
}
# Now ALL of the files should have names in the form of
# numbers followed by "-DictationCounts_KP.txt"
# we get all names that match the wildcard pattern
# [0-9]*-DictationCounts_KP.txt
# and sort them DESCENDING. Given the naming convention,
# that means the most recent existing file is going to be first
# in the returned list.
gc (Get-ChildItem $sharepath\[0-9]*-$filename | sort Name -Desc)[0]

"TimParker" <timpar@xxxxxx> wrote in message
news:2fc3571b-6513-4126-a8ec-3963cbe47d57@xxxxxx
Quote:

> I am looking for a bit of help. I have a couple of remote
> transcriptionists and I have a report for all our transcriptionists
> that reports on the total number of dictations that they have
> currently assigned to them. This report is still wrong a lot of times,
> based on whether or not these two are connected and a have a current
> file from them.
>
> I have the following that I am doing:
>
> $user7 = "User Name"
> $filepath7 = "\\wkstn0020\newsletter\DictationCounts_KP.txt"
>
> $testUser = Test-Path $filepath7
> if($testUser -eq $TRUE){
> [INT]$count7 = (gc $filepath7)
> }
> elseif ($testUser -eq $FALSE){
> [INT]$count7 = 0
> }
>
> At the end of the job I clean up these files. Adding the Date to the
> files 20090618-
>
> #Cleanup/Rename two temp files for Kathy and Christina
> $rendate = (get-date)
> $rendate=$rendate.tostring("yyyyMMdd")
> Rename-Item \\wkstn0020\newsletter\DictationCounts_KP.txt $rendate-
> DictationCounts_KP.txt
>
> I would like to change the false portion above to start reading
> backwards from the previous day, if it finds a file then use that
> count instead of the zero. I am starting to confuse myself as I am
> thinking too hard about this I think. If for some reason (weekend,
> vacation, days off) it could be several days back before I would have
> a file, which would be about as accurate as I can get.
>
> Thanks for any help.
>
> Tim
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Recoving 7 Zip Archive - Cannot open file 'xampp.7z' as archive Vista file management
Find hidden file, Reading from txt file VB Script
Automatically Move Read Email to an Archive Folder after reading Vista mail
zip file integration... other archive types? Vista file management
accodamento file archivio outlook archive.pst Vista mail


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46