Sign in to follow this  
Followers 0
Bert

Looking for a example...

7 posts in this topic

#1 ·  Posted (edited)

I'm not quite sure just how to perform a search without a million hits and having to weed through to find what I want so here goes. I'm hoping someone has something like this or something close enough I can tweak to do what I need it to do:

I got a application that makes a file each time it is ran. When it makes the file, it will be named like the following example:

2UA5260MG0 XXXXX 02.15.2006 13.51.24.csv

I will be using this program all the time, and discovered a possible bug. The bug is something I'm NOT allowed to fix. (even discuss with management for that matter) :o Due to this bug, I have to now keep track of these files. (to cover my butt) No biggie, but I like to have it cataloged in folders with the folder names having the following naming convention:

week of 2_7_06

week of 2_14_06

The pseudo code would go something like this:

1. program runs and file is created. The file is made in the same working directory as the program (can't change this)

2. The script checks the new file and gets its creation date.

3. The script checks the sub folders in the working directory to find the latest created folder.

4. If the folder was made the week before, as in last week (M - F), a new folder is made, then step 6

5. If the folder was made in the current week, then step 6

6. The file is moved to the folder for that week.

I hope this makes sence.

Edited by vollyman

Share this post


Link to post
Share on other sites



What management team would want faulty software out there if it could be fixed... That sounds rather ludicrous!

Would make me look for another opportunity for those that expect and demand perfection.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

I know, faulty software...I tried running that up the flagpoll, and I got yelled at something fierce. (still smarting from that one too) The general feeling about the program (that was designed by someone internally in the company, and don't get me started about that) is that it is along the lines of :o

In any case, I'm stuck with it. On a good note, I did design a front end that made a tremendous improvement to the thing. Too bad I can't share it for the fear of getting :geek: again. I'm hoping in a few weeks after everyone starts showing all the trouble this thing causes, I can whip out my fix and be in the good graces of management again. sigh.

Anyone got what I'm looking for? please????? ;)

Share this post


Link to post
Share on other sites

I'm not quite sure just how to perform a search without a million hits and having to weed through to find what I want so here goes. I'm hoping someone has something like this or something close enough I can tweak to do what I need it to do:

I got a application that makes a file each time it is ran. When it makes the file, it will be named like the following example:

2UA5260MG0 XXXXX 02.15.2006 13.51.24.csv

I will be using this program all the time, and discovered a possible bug. The bug is something I'm NOT allowed to fix. (even discuss with management for that matter) :o Due to this bug, I have to now keep track of these files. (to cover my butt) No biggie, but I like to have it cataloged in folders with the folder names having the following naming convention:

week of 2_7_06

week of 2_14_06

The pseudo code would go something like this:

1. program runs and file is created. The file is made in the same working directory as the program (can't change this)

2. The script checks the new file and gets its creation date.

3. The script checks the sub folders in the working directory to find the latest created folder.

4. If the folder was made the week before, as in last week (M - F), a new folder is made, then step 6

5. If the folder was made in the current week, then step 6

6. The file is moved to the folder for that week.

I hope this makes sence.

Just to see if I could do it, here is a working sample based on your pseudo code.

Good luck...

Dick

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.1++
; Author:        Dick Bronsdijk
;
; Script Function:  Move file to Dated Directory
;                  Create Directory if it doen't exist
;                  New directory is created on Monday (weekday = 0)
;
; !!!! Needs BETA version of AutoIt
; ----------------------------------------------------------------------------

#include <Date.au3>

Opt("MustDeclareVars", 1)

Main()

Exit

Func Main()
    Local $sFileName, $aDate, $aFDate, $iDay, $iMon, $iYear, $iWeek, $sWeek, $iCurr, $sJulDate, $sNewName
    Local $hFile = FileFindFirstFile("*.csv")
    While True
        $sFileName = FileFindNextFile($hFile)
        If @error Then ExitLoop
        $aDate  = StringSplit($sFileName, ". ") ; Get date from file name
;       $aFDate = FileGetTime($sFileName, ". "); Get real file date
        If IsArray($aDate) Then
            $iMon  = Number($aDate[3]); [0] for Year when $aFDate
            $iDay  = Number($aDate[4]); [1] for Month when $aFDate 
            $iYear = Number($aDate[5]); [2] for Day when $aFDate
;           $iWeek = _WeekNumberISO($iYear, $iMon, $iDay); Get week number
;           $sWeek = StringFormat("%04d_Week_%02d", $iYear, $iWeek); Format = "2006_Week_07"
            $iCurr = _DateToDayOfWeekISO($iYear, $iMon, $iDay)
            $sJulDate = _DateToDayValue($iYear, $iMon, $iDay)
            $sJulDate = _DayValueToDate($sJulDate-$iCurr, $iYear, $iMon, $iDay)
            $sNewName = StringFormat("week of %d_%d_%d", $iMon, $iDay, $iYear); Format "week of YYYY_MM_DD" would more logical for sequence reasons
            If Not FileExists($sNewName) Then
                DirCreate($sNewName)
            EndIf
            FileMove($sFileName, $sNewName & "\" & $sFileName)
        EndIf
    WEnd
    FileClose($hFile)
EndFunc

Share this post


Link to post
Share on other sites

Tried it this morning, and it works great! :o

I needed to make a few changes to it, but nothing major. Here is the code I ended up using:

Thank you!

CODE
Func _filemove1()

Local $sFileName, $aDate, $aFDate, $iDay, $iMon, $iYear, $iWeek, $sWeek, $iCurr, $sJulDate, $sNewName

Local $hFile = FileFindFirstFile("*.csv") ;finds CSV file.

While True

$sFileName = FileFindNextFile($hFile)

If @error Then ExitLoop

$aDate = StringSplit($sFileName, ". ") ; Get date from file name

; $aFDate = FileGetTime($sFileName, ". "); Get real file date

If IsArray($aDate) Then

$iMon = Number($aDate[3]); [0] for Year when $aFDate

$iDay = Number($aDate[4]); [1] for Month when $aFDate

$iYear = Number($aDate[5]); [2] for Day when $aFDate

; $iWeek = _WeekNumberISO($iYear, $iMon, $iDay); Get week number

; $sWeek = StringFormat("%04d_Week_%02d", $iYear, $iWeek); Format = "2006_Week_07"

$iCurr = _DateToDayOfWeekISO($iYear, $iMon, $iDay)

$sJulDate = _DateToDayValue($iYear, $iMon, $iDay)

$sJulDate = _DayValueToDate($sJulDate-$iCurr, $iYear, $iMon, $iDay)

$sNewName = StringFormat("week of %d_%d_%d", $iMon, $iDay, $iYear); Format "week of YYYY_MM_DD" would more logical for sequence reasons

If Not FileExists($sNewName) Then

DirCreate($sNewName)

EndIf

FileMove($sFileName, $sNewName & "\Active\" & $sFileName, 8)

EndIf

WEnd

FileClose($hFile)

EndFunc

Share this post


Link to post
Share on other sites

Tried it this morning, and it works great! :o

I needed to make a few changes to it, but nothing major. Here is the code I ended up using:

Thank you!

CODE
Func _filemove1()

Local $sFileName, $aDate, $aFDate, $iDay, $iMon, $iYear, $iWeek, $sWeek, $iCurr, $sJulDate, $sNewName

Local $hFile = FileFindFirstFile("*.csv") ;finds CSV file.

While True

$sFileName = FileFindNextFile($hFile)

If @error Then ExitLoop

$aDate = StringSplit($sFileName, ". ") ; Get date from file name

; $aFDate = FileGetTime($sFileName, ". "); Get real file date

If IsArray($aDate) Then

$iMon = Number($aDate[3]); [0] for Year when $aFDate

$iDay = Number($aDate[4]); [1] for Month when $aFDate

$iYear = Number($aDate[5]); [2] for Day when $aFDate

; $iWeek = _WeekNumberISO($iYear, $iMon, $iDay); Get week number

; $sWeek = StringFormat("%04d_Week_%02d", $iYear, $iWeek); Format = "2006_Week_07"

$iCurr = _DateToDayOfWeekISO($iYear, $iMon, $iDay)

$sJulDate = _DateToDayValue($iYear, $iMon, $iDay)

$sJulDate = _DayValueToDate($sJulDate-$iCurr, $iYear, $iMon, $iDay)

$sNewName = StringFormat("week of %d_%d_%d", $iMon, $iDay, $iYear); Format "week of YYYY_MM_DD" would more logical for sequence reasons

If Not FileExists($sNewName) Then

DirCreate($sNewName)

EndIf

FileMove($sFileName, $sNewName & "\Active\" & $sFileName, 8)

EndIf

WEnd

FileClose($hFile)

EndFunc

Glad I could help you.

Dick

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0