Jump to content

Move files created yesterday


skysel
 Share

Recommended Posts

Nope, neither water's script is not working. We're missing something here...

Complete script looks like this now:

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

$srcfolder = "C:\Program Files\Microsoft Dynamics CRM\Trace"

$FileList = _FileListToArray($srcfolder)

For $i = 1 To UBound($FileList) - 1
    $FileTime = FileGetTime($srcfolder & "\" & $FileList[$i], 0)
    If $FileTime[0] = @YEAR And $FileTime[1] = @MON And $FileTime[2] = @MDAY Then
        FileMove($srcfolder & "\" & $FileList[$i], "\\server.local\TraceLogs\CRM-WEB-01")
    EndIf
Next

For $i = 1 To UBound($FileList) - 1
    $FileTime = FileGetTime($srcfolder & "\" & $FileList[$i], 0)
    If $FileTime[0] & "/" & $FileTime[1] & "/" & $FileTime[2] = _DateAdd("D", -1, _NowCalcDate()) Then
    FileMove($srcfolder & "\" & $FileList[$i], "\\server.local\TraceLogs\CRM-WEB-01")
    EndIf
Next

First part works flawlessly, second however still doesn't :-)

Link to comment
Share on other sites

  • Replies 54
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Does this code work?

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 the feeling that I'm blind, deaf and stupid (today) :D

Why should I take into account month changes or years? This is calculated by _DateAdd. It returns a string of yesterdays date which is compared against the string of the filedate (both in the same format).

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

One thing that took some time for me to understand was that _FileGetTime needs the THIRD parameter to be set to 1 to return the date as a string.

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

Yes, but in your post you've set parameter #2 (Flag to indicate which timestamp) so the date was still returned as an array.

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

I know why it doesn't work.

FileGetTime returns YYYYMMDDHHMMSS in string mode. So...

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

$srcfolder = "C:\Program Files\Microsoft Dynamics CRM\Trace"

$FileList = _FileListToArray($srcfolder)

$arTime = StringSplit(_DateAdd("D", -1, _NowCalcDate()), "/")

Dim $newTime
For $a = 1 To UBound($arTime) - 1
    $newTime &= $arTime[$a]
Next

For $i = 1 To UBound($FileList) - 1
    $FileTime = FileGetTime($srcfolder & "\" & $FileList[$i], 0, 1)
    ConsoleWrite(StringTrimRight($FileTime, 6) & @CRLF)
    If StringTrimRight($FileTime, 6) = $newTime Then
        ConsoleWrite("Found you!" & @CRLF)
        FileMove($srcfolder & "\" & $FileList[$i], "\\server.local\TraceLogs\")
    EndIf
Next
Yes, the first loop could be done better but it works. Edited by JamesBrooks
Link to comment
Share on other sites

Just tested it. I've only removed ConsoleWrite line. Still not working. First part - moving files created today works ok, second part files created yesterday/older doesn't work. Files created yesterday are not write-protected, I have full permissions to move those files.

I know why it doesn't work.

FileGetTime returns YYYYMMDDHHMMSS in string mode. So...

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

$srcfolder = "C:\Program Files\Microsoft Dynamics CRM\Trace"

$FileList = _FileListToArray($srcfolder)

$arTime = StringSplit(_DateAdd("D", -1, _NowCalcDate()), "/")

Dim $newTime
For $a = 1 To UBound($arTime) - 1
    $newTime &= $arTime[$a]
Next

For $i = 1 To UBound($FileList) - 1
    $FileTime = FileGetTime($srcfolder & "\" & $FileList[$i], 0, 1)
    ConsoleWrite(StringTrimRight($FileTime, 6) & @CRLF)
    If StringTrimRight($FileTime, 6) = $newTime Then
        ConsoleWrite("Found you!" & @CRLF)
        FileMove($srcfolder & "\" & $FileList[$i], "\\server.local\TraceLogs\")
    EndIf
Next
Yes, the first loop could be done better but it works.

Link to comment
Share on other sites

Ok just for the sake of script's health I'm posting it again. I've just attached your part of the code.

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

$srcfolder = "C:\Program Files\Microsoft Dynamics CRM\Trace"

$FileList = _FileListToArray($srcfolder)

For $i = 1 To UBound($FileList) - 1
    $FileTime = FileGetTime($srcfolder & "\" & $FileList[$i], 0)
    If $FileTime[0] = @YEAR And $FileTime[1] = @MON And $FileTime[2] = @MDAY Then
        FileMove($srcfolder & "\" & $FileList[$i], "\\server.local\TraceLogs")
    EndIf
Next

$FileList = _FileListToArray($srcfolder)

$arTime = StringSplit(_DateAdd("D", -1, _NowCalcDate()), "/")

Dim $newTime
For $a = 1 To UBound($arTime) - 1
    $newTime &= $arTime[$a]
Next

For $i = 1 To UBound($FileList) - 1
    $FileTime = FileGetTime($srcfolder & "\" & $FileList[$i], 0, 1)
    ConsoleWrite(StringTrimRight($FileTime, 6) & @CRLF)
    If StringTrimRight($FileTime, 6) = $newTime Then
            FileMove($srcfolder & "\" & $FileList[$i], "\\server.local\TraceLogs")
    EndIf
Next
Link to comment
Share on other sites

I tried it myself (but without FileMove), it worked fine for me as well.

What does "doesn't work" mean?

  • Do you get any error messages?
  • Are the files copied to the target?
  • I'm not sure if AutoIt supports UNC notation (\\server.local\TraceLogs\). Can you try to move the files to - lets say - C:\temp?
  • Can you uncomment or reinsert the line
    ConsoleWrite("Found you!" & @CRLF)
    so we know we got the date comparison right?

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

Hi water,

by doesn't work I mean:

- No error messages

- Files are not copied to the target

- AutoIt supports UNC (Check the first part of the script, this very first part works without problems for few days already on a Win2k3 server)

- After reinsertion of ConsoleWrite line, I still get no messages whatsoever.

I tried it myself (but without FileMove), it worked fine for me as well.

What does "doesn't work" mean?

  • Do you get any error messages?
  • Are the files copied to the target?
  • I'm not sure if AutoIt supports UNC notation (\\server.local\TraceLogs\). Can you try to move the files to - lets say - C:\temp?
  • Can you uncomment or reinsert the line
    ConsoleWrite("Found you!" & @CRLF)
    so we know we got the date comparison right?
Edited by skysel
Link to comment
Share on other sites

Another try Posted Image

I extended the example that works for me to display yesterday's date and the date of all files plus any error message that might occur when moving the file (maybe the target disk is full or the target directory isn't created yet ...)

#include <Date.au3>
#include <array.au3>
#include <file.au3>

$srcfolder = "C:\Program Files\Microsoft Dynamics CRM\Trace"

$FileList = _FileListToArray($srcfolder)

$arTime = StringSplit(_DateAdd("D", -1, _NowCalcDate()), "/")

Dim $newTime
For $a = 1 To UBound($arTime) - 1
    $newTime &= $arTime[$a]
Next
ConsoleWrite("Yesterdays Date: " & $newtime & @CRLF)
For $i = 1 To UBound($FileList) - 1
    $FileTime = FileGetTime($srcfolder & "\" & $FileList[$i], 0, 1)
    ConsoleWrite("File: " & $srcfolder & "\" & $FileList[$i] & " File Date: " & StringTrimRight($FileTime, 6) & @CRLF)
    If StringTrimRight($FileTime, 6) = $newTime Then
    ConsoleWrite("Got You! " & $FileList[$i] & @CRLF)
    FileMove($srcfolder & "\" & $FileList[$i], "\\server.local\TraceLogs\")
        If @error > 0 Then MsgBox(0,"","Error " & @error & " when moving file " & $srcfolder & "\" & $FileList[$i])
    EndIf
Next

Could you give it a try and report the results from the SciTe console?

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

This time I've only used your part of script and executed it on the server. Script runs. No error messages. No nothing.

Still doesn't move the files. Target directory has 60GB of free space.

I cannot run the script from the editor, since I am not allowed to install any additional software to the server. Could it be replaced by MsgBox()?

Edited by skysel
Link to comment
Share on other sites

But the SciTE console should return a lot of information. How about that? Or do you compile the script and then run the exe?

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

Sorry, missed that line.

I changed the script so that all messages are written to a log file C:\temp\autoit.txt

Could you please post this log file?

#include <Date.au3>
#include <array.au3>
#include <file.au3>

$srcfolder = "C:\Program Files\Microsoft Dynamics CRM\Trace"
$Logfile = "C:\temp\autoit.txt"
$FileList = _FileListToArray($srcfolder)
$arTime = StringSplit(_DateAdd("D", -1, _NowCalcDate()), "/")
Dim $newTime
For $a = 1 To UBound($arTime) - 1
    $newTime &= $arTime[$a]
Next
FileDelete($Logfile)
FileWriteLine($Logfile,"Yesterdays Date: " & $newtime)
For $i = 1 To UBound($FileList) - 1
    $FileTime = FileGetTime($srcfolder & "\" & $FileList[$i], 0, 1)
    FileWriteLine($Logfile,"File: " & $srcfolder & "\" & $FileList[$i] & " File Date: " & StringTrimRight($FileTime, 6))
    If StringTrimRight($FileTime, 6) = $newTime Then
    FileWriteLine($Logfile,"Got You! " & $FileList[$i])
    FileMove($srcfolder & "\" & $FileList[$i], "\\server.local\TraceLogs\")
        If @error > 0 Then FileWriteLine($Logfile,"Error " & @error & " when moving file " & $srcfolder & "\" & $FileList[$i])
    EndIf
Next

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...