Jump to content

Move files created yesterday


skysel
 Share

Recommended Posts

Hi, I get this output:

Yesterdays Date: 20100125

File: C:\Program Files\Microsoft Dynamics CRM\Trace\WEB-01-w3wp-Ttk.Crm.DocumentManagement-20100126-1.log File Date: 20100126

File: C:\Program Files\Microsoft Dynamics CRM\Trace\WEB-01-w3wp-Ttk.Crm.FraudPrevention-20100125-1.log File Date: 20100125

Got You! WEB-01-w3wp-Ttk.Crm.FraudPrevention-20100125-1.log

File: C:\Program Files\Microsoft Dynamics CRM\Trace\WEB-01-w3wp-Ttk.Crm.FraudPrevention-20100126-1.log File Date: 20100126

File: C:\Program Files\Microsoft Dynamics CRM\Trace\WEB-01-w3wp-Ttk.Crm.GetCustomerNumbers-20100125-1.log File Date: 20100125

Got You! WEB-01-w3wp-Ttk.Crm.GetCustomerNumbers-20100125-1.log

File: C:\Program Files\Microsoft Dynamics CRM\Trace\WEB-01-w3wp-Ttk.Crm.GetCustomerNumbers-20100126-1.log File Date: 20100126

File: C:\Program Files\Microsoft Dynamics CRM\Trace\WEB-01-w3wp-Ttk.Crm.SmartForms-20100125-1.log File Date: 20100125

Got You! WEB-01-w3wp-Ttk.Crm.SmartForms-20100125-1.log

File: C:\Program Files\Microsoft Dynamics CRM\Trace\WEB-01-w3wp-Ttk.Crm.SmartForms-20100126-1.log File Date: 20100126

File: C:\Program Files\Microsoft Dynamics CRM\Trace\WEB-01-w3wp-wwwroot-20100125-2.log File Date: 20100125

Got You! WEB-01-w3wp-wwwroot-20100125-2.log

File: C:\Program Files\Microsoft Dynamics CRM\Trace\WEB-01-w3wp-wwwroot-20100126-1.log File Date: 20100126

File: C:\Program Files\Microsoft Dynamics CRM\Trace\WEB-01-w3wp-wwwroot-20100126-2.log File Date: 20100126

It appears it should work, but for some strange reason it won't. I'm off from work for today, so we can continue this tomorrow :D

This is ridiculous! The last script I posted worked fine when I tried moving files from a sub-directory on my Desktop to my Desktop.

skysel, run waters script, post the output and let's see what the hell is going on...

Link to comment
Share on other sites

  • Replies 54
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Every time it outputs "Got you!" that means the match has been made and the file should move! We could do a nice test now to see if the file has been moved by doing this. Wait nevermind, I've just seen this line:

If @error > 0 Then FileWriteLine($Logfile,"Error " & @error & " when moving file " & $srcfolder & "\" & $FileList[$i])
And now, as there were no errors, we have to assume that there is something wrong with the server. If the files are matched, the date works, then there must be a server fault.

Right, so I've commented everything on the script and made a couple of changes. It now logs the file if it wasn't found. Also, if the directory the file is supposed to be moved to doesn't exist, it creates it - just in case.

#include <Date.au3>
#include <File.au3>

$srcfolder = "C:\Program Files\Microsoft Dynamics CRM\Trace" ; Set the source folder
$Logfile = "C:\temp\autoit.txt" ; Set the log file
$FileList = _FileListToArray($srcfolder) ; List all files in the array
$arTime = StringSplit(_DateAdd("D", -1, _NowCalcDate()), "/") ; Split yesterdays date up by the / delimeter
Dim $newTime
For $a = 1 To UBound($arTime) - 1
    $newTime &= $arTime[$a] ; Everytime we find a piece of the date, concatenate it
Next
FileDelete($Logfile) ; Delete the log file
FileWriteLine($Logfile, "Yesterdays Date: " & $newTime) ; Write yesterdays date to it

For $i = 1 To UBound($FileList) - 1 ; For each file in the array
    $FileTime = StringTrimRight(FileGetTime($srcfolder & "\" & $FileList[$i], 0, 1), 6) ; Get its creation date as a string and trim the time off
    FileWriteLine($Logfile, "File: " & $srcfolder & "\" & $FileList[$i] & " File Date: " & $FileTime & @CRLF) ; Write the log file
    If $FileTime = $newTime Then ; If the file date matches the current date
        FileWriteLine($Logfile, "Found file: " & $FileList[$i] & @CRLF)
        FileMove($srcfolder & "\" & $FileList[$i], "\\server.local\TraceLogs\", 8) ; Move the file
        If @error Then FileWriteLine($Logfile, "Error " & @error & " when moving file " & $srcfolder & "\" & $FileList[$i]) ; If there is an error, log it
    Else
        FileWriteLine($Logfile, "Could not find file: "  & $srcfolder & "\" & $FileList[$i] & @CRLF) ; If the file wasn't found, log it
    EndIf
Next
Edited by JamesBrooks
Link to comment
Share on other sites

Ok this is really weird. Script now moved some files (2-3, but should move more)... The output is logged as:

Yesterdays Date: 20100126
File: C:\Program Files\Microsoft Dynamics CRM\Trace\CRM-WEB-01-w3wp-Ttk.Crm.DocumentManagement-20100126-1.log File Date: 20100126
Found file: CRM-WEB-01-w3wp-Ttk.Crm.DocumentManagement-20100126-1.log
File: C:\Program Files\Microsoft Dynamics CRM\Trace\CRM-WEB-01-w3wp-Ttk.Crm.DocumentManagement-20100127-1.log File Date: 20100127
Could not find file: C:\Program Files\Microsoft Dynamics CRM\Trace\CRM-WEB-01-w3wp-Ttk.Crm.DocumentManagement-20100127-1.log
File: C:\Program Files\Microsoft Dynamics CRM\Trace\CRM-WEB-01-w3wp-Ttk.Crm.FraudPrevention-20100125-1.log File Date: 20100125
Could not find file: C:\Program Files\Microsoft Dynamics CRM\Trace\CRM-WEB-01-w3wp-Ttk.Crm.FraudPrevention-20100125-1.log
File: C:\Program Files\Microsoft Dynamics CRM\Trace\CRM-WEB-01-w3wp-Ttk.Crm.FraudPrevention-20100126-1.log File Date: 20100126
Found file: CRM-WEB-01-w3wp-Ttk.Crm.FraudPrevention-20100126-1.log
File: C:\Program Files\Microsoft Dynamics CRM\Trace\CRM-WEB-01-w3wp-Ttk.Crm.FraudPrevention-20100127-1.log File Date: 20100127
Could not find file: C:\Program Files\Microsoft Dynamics CRM\Trace\CRM-WEB-01-w3wp-Ttk.Crm.FraudPrevention-20100127-1.log
File: C:\Program Files\Microsoft Dynamics CRM\Trace\CRM-WEB-01-w3wp-Ttk.Crm.GetCustomerNumbers-20100125-1.log File Date: 20100125
Could not find file: C:\Program Files\Microsoft Dynamics CRM\Trace\CRM-WEB-01-w3wp-Ttk.Crm.GetCustomerNumbers-20100125-1.log
File: C:\Program Files\Microsoft Dynamics CRM\Trace\CRM-WEB-01-w3wp-Ttk.Crm.GetCustomerNumbers-20100126-1.log File Date: 20100126
Found file: CRM-WEB-01-w3wp-Ttk.Crm.GetCustomerNumbers-20100126-1.log
File: C:\Program Files\Microsoft Dynamics CRM\Trace\CRM-WEB-01-w3wp-Ttk.Crm.SmartForms-20100125-1.log File Date: 20100125
Could not find file: C:\Program Files\Microsoft Dynamics CRM\Trace\CRM-WEB-01-w3wp-Ttk.Crm.SmartForms-20100125-1.log
File: C:\Program Files\Microsoft Dynamics CRM\Trace\CRM-WEB-01-w3wp-Ttk.Crm.SmartForms-20100126-1.log File Date: 20100126
Found file: CRM-WEB-01-w3wp-Ttk.Crm.SmartForms-20100126-1.log
File: C:\Program Files\Microsoft Dynamics CRM\Trace\CRM-WEB-01-w3wp-Ttk.Crm.SmartForms-20100127-1.log File Date: 20100127
Could not find file: C:\Program Files\Microsoft Dynamics CRM\Trace\CRM-WEB-01-w3wp-Ttk.Crm.SmartForms-20100127-1.log
File: C:\Program Files\Microsoft Dynamics CRM\Trace\CRM-WEB-01-w3wp-wwwroot-20100125-2.log File Date: 20100125
Could not find file: C:\Program Files\Microsoft Dynamics CRM\Trace\CRM-WEB-01-w3wp-wwwroot-20100125-2.log
File: C:\Program Files\Microsoft Dynamics CRM\Trace\CRM-WEB-01-w3wp-wwwroot-20100126-1.log File Date: 20100126
Found file: CRM-WEB-01-w3wp-wwwroot-20100126-1.log
File: C:\Program Files\Microsoft Dynamics CRM\Trace\CRM-WEB-01-w3wp-wwwroot-20100126-2.log File Date: 20100126
Found file: CRM-WEB-01-w3wp-wwwroot-20100126-2.log
File: C:\Program Files\Microsoft Dynamics CRM\Trace\CRM-WEB-01-w3wp-wwwroot-20100126-3.log File Date: 20100126
Found file: CRM-WEB-01-w3wp-wwwroot-20100126-3.log
File: C:\Program Files\Microsoft Dynamics CRM\Trace\CRM-WEB-01-w3wp-wwwroot-20100127-1.log File Date: 20100127
Could not find file: C:\Program Files\Microsoft Dynamics CRM\Trace\CRM-WEB-01-w3wp-wwwroot-20100127-1.log

Every time it outputs "Got you!" that means the match has been made and the file should move! We could do a nice test now to see if the file has been moved by doing this. Wait nevermind, I've just seen this line:

If @error > 0 Then FileWriteLine($Logfile,"Error " & @error & " when moving file " & $srcfolder & "\" & $FileList[$i])
And now, as there were no errors, we have to assume that there is something wrong with the server. If the files are matched, the date works, then there must be a server fault.

Right, so I've commented everything on the script and made a couple of changes. It now logs the file if it wasn't found. Also, if the directory the file is supposed to be moved to doesn't exist, it creates it - just in case.

#include <Date.au3>
#include <File.au3>

$srcfolder = "C:\Program Files\Microsoft Dynamics CRM\Trace" ; Set the source folder
$Logfile = "C:\temp\autoit.txt" ; Set the log file
$FileList = _FileListToArray($srcfolder) ; List all files in the array
$arTime = StringSplit(_DateAdd("D", -1, _NowCalcDate()), "/") ; Split yesterdays date up by the / delimeter
Dim $newTime
For $a = 1 To UBound($arTime) - 1
    $newTime &= $arTime[$a] ; Everytime we find a piece of the date, concatenate it
Next
FileDelete($Logfile) ; Delete the log file
FileWriteLine($Logfile, "Yesterdays Date: " & $newTime) ; Write yesterdays date to it

For $i = 1 To UBound($FileList) - 1 ; For each file in the array
    $FileTime = StringTrimRight(FileGetTime($srcfolder & "\" & $FileList[$i], 0, 1), 6) ; Get its creation date as a string and trim the time off
    FileWriteLine($Logfile, "File: " & $srcfolder & "\" & $FileList[$i] & " File Date: " & $FileTime & @CRLF) ; Write the log file
    If $FileTime = $newTime Then ; If the file date matches the current date
        FileWriteLine($Logfile, "Found file: " & $FileList[$i] & @CRLF)
        FileMove($srcfolder & "\" & $FileList[$i], "\\server.local\TraceLogs\", 8) ; Move the file
        If @error Then FileWriteLine($Logfile, "Error " & @error & " when moving file " & $srcfolder & "\" & $FileList[$i]) ; If there is an error, log it
    Else
        FileWriteLine($Logfile, "Could not find file: "  & $srcfolder & "\" & $FileList[$i] & @CRLF) ; If the file wasn't found, log it
    EndIf
Next

Link to comment
Share on other sites

Script now moved some files (2-3, but should move more)...

According to your log file it should have moved 7 files. How many did it actually move (2 or 3?) and how many should it move (7 or more?)

Could you please be as specific as possible?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Hah, I figured out what was wrong! On the FileMove function, I've added flag 1 (means overwrite existing files, etc). And now the script works great... go figure? :D Don't know what and why but it is working as it should. Thank you both for your extensive help!

Link to comment
Share on other sites

Hah, I figured out what was wrong! On the FileMove function, I've added flag 1 (means overwrite existing files, etc). And now the script works great... go figure? :D Don't know what and why but it is working as it should. Thank you both for your extensive help!

Posted Image Edited by JamesBrooks
Link to comment
Share on other sites

I agree whole-heartedly!

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

James, is it that bad? :D Yeah I really don't know why the flag 1 on FileMove - because when the files moved they couldn't exist already on destination folder so files should get moved without overwrite flag! It really puzzles me :huggles:

Link to comment
Share on other sites

James, is it that bad? :D Yeah I really don't know why the flag 1 on FileMove - because when the files moved they couldn't exist already on destination folder so files should get moved without overwrite flag! It really puzzles me :huggles:

It's kind of annoying. A tiny issue like that took three of us hours to fix.

I'd either completely ignore the flag or set it or set it to 9:

1 = overwrite existing files 8 = Create destination directory structure if it doesn't exist (See Remarks).

So 1+8 = Create/Overwrite if it doesn't exist Edited by JamesBrooks
Link to comment
Share on other sites

Haha, mabye that feature should be implemented in the next release of auto-it .. combining flags like you said.. 1+8=9 :D

You can already use it. Set the flag to 9 and it works!

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I get off this topic :D. Otherwise I fear to get brain cancer :huggles:

I need all my neurons for the Active Directory UDF (see signature).

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...