Sign in to follow this  
Followers 0
skysel

Need some help completing script - file dates

16 posts in this topic

#1 ·  Posted (edited)

I need some help with this piece of code (details written below):

Dim $filename
$filename = "C:\" & @UserName & "." &  @MDAY & "." &  @MON & "." @YEAR & ".7z"
RunWait ( "7za.exe a -t7z -mx=9 " & $filename & "C:\Program Files\Someprogram\IC71\logs\*.log" )
FileCopy ($filename, "\\machine\shareddir")

Dim $filename
$filename = "C:\" & "." &  @MDAY & "." &  @MON & "." @YEAR & "-voice1.7z"
RunWait ( "7za.exe a -t7z -mx=9 " & filename & "\\share\logs\voice1.log")
FileCopy ($filename, @UserProfileDir & "Desktop\")
Dim $filename
$filename = "C:\" & "." &  @MDAY & "." &  @MON & "." @YEAR & "-voice2.7z"
RunWait ( "7za.exe a -t7z -mx=9 " & filename & "\\share\logs\voice2.log")
FileCopy ($filename, @UserProfileDir & "Desktop\")

On the first part of the code, when copying the logs, only logs created TODAY should get packed up. A compressed file should be named WindowsLogonName-dd-mm-yy. Now when the compressed file copies into network share and if there is a same name already in that directory, filename should rename to WindowsLogonName-dd-mm-yy-1.

The second part of the code, compressed files should be copied to userprofile\desktop. If the filename exists, it should be renamed again :) so it would be dd.mm.yy-voice1-1.log. I hope I made myself clear enough on what I want to accomplish :)

Edited by skysel

Share this post


Link to post
Share on other sites



Didn't really see your question or something, but something you have to do first is to fix thess lines:

@UserProfileDir & "Desktop\"oÝ÷ Øl¥u·ºÚ"µÍÙÙ[Q   [È ][ÝÉÌLÑÚÝÜ   ÌLÉ][Ý

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Didn't really see your question or something

On the first part of the code, when copying the logs, only logs (files) created TODAY should get packed up. A compressed file should be named WindowsLogonName-dd-mm-yy.- help here Now when the compressed file copies into network share and if there is a same name already in that directory, filename should rename to WindowsLogonName-dd-mm-yy-1. - help here

The second part of the code, compressed files should be copied to userprofile\desktop. If the filename exists, it should be renamed - help here again :) so it would be dd.mm.yy-voice1-1.log. I hope I made myself clear enough on what I want to accomplish

Edited by skysel

Share this post


Link to post
Share on other sites

anyone? :)

Share this post


Link to post
Share on other sites

Sorry for the annoyance.. but i really need this working :)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Part 1:

Dim $sourceFolder = "C:\"
Dim $filename = @UserName & "." &  @MDAY & "." &  @MON & "." & @YEAR
Dim $ext = ".7z"
Dim $sharedFolder = "\\machine\shareddir"

RunWait ( "7za.exe a -t7z -mx=9 " & $sourceFolder & $filename & $ext & " C:\Program Files\Someprogram\IC71\logs\*.log" )

If FileExists($sharedFolder & "\" & $filename & $ext) Then
$num = 1
Do
$newFilename = $filename & "-" & $num & $ext
$num += 1
Until NOT FileExists($sharedFolder & "\" & $newFilename)
EndIf

FileCopy ($sourceFolder & "\" & $filename & $ext, $sharedFolder & "\" & $newFilename)
Edited by weaponx

Share this post


Link to post
Share on other sites

It's probably better to use a function for doing this type of incremental filecopy, since you have to use it for multiple files.

incrementalCopy(@DesktopDir & "\Source\New Text document.txt", @DesktopDir & "\Destination")

;Increment trailing digit in filename until its not found in the destination, then copy
Func incrementalCopy($sSourcePath, $sDestinationFolder)
    
    ;Return if source file isn't found
    If NOT FileExists($sSourcePath) Then
        Return SetError(1,0,1)
    EndIf
    
    ;Prefix increment digits with a character
    Local $prefix = "-"
    
    ;Seperate source folder & filename
    Local $pathArray = StringSplit($sSourcePath, "\")
    
    ;Store source filename
    Local $sSourceFileName = $pathArray[$pathArray[0]]
    
    ;Copy source filename to destination filename by default
    Local $sDestinationFileName = $sSourceFileName
    
    ;Cleanup destination folder path
    If StringRight($sDestinationFolder, 1) <> "\" Then $sDestinationFolder &= "\"
    
    ;Begin count at one
    $count = 1
    
    ;If the file doesn't exist in the destination, proceed directly to filecopy
    If FileExists($sDestinationFolder & $sSourceFileName) Then
        Do
            ;Increment filename, with special exception for tar.gz files so they don't become mangled
            $sDestinationFileName = StringRegExpReplace($sSourceFileName, "((\.tar)?\.[a-z]+)$",$prefix & $count & "\1")
            ConsoleWrite($sDestinationFileName & @CRLF)
            $count += 1
        Until NOT FileExists($sDestinationFolder & $sDestinationFileName)
    EndIf
    
    ;Perform copy
    $return = FileCopy($sSourcePath, $sDestinationFolder & $sDestinationFileName)
    
    Return $return

    
    ;MsgBox(0,"","Source: " & $sSourcePath & @CRLF & "Destination: " & $sDestinationFolder & $sDestinationFileName)
EndFunc

Share this post


Link to post
Share on other sites

Part 1:

Dim $sourceFolder = "C:\"
Dim $filename = @UserName & "." &  @MDAY & "." &  @MON & "." & @YEAR
Dim $ext = ".7z"
Dim $sharedFolder = "\\machine\shareddir"

RunWait ( "7za.exe a -t7z -mx=9 " & $sourceFolder & $filename & $ext & " C:\Program Files\Someprogram\IC71\logs\*.log" )

If FileExists($sharedFolder & "\" & $filename & $ext) Then
$num = 1
Do
$newFilename = $filename & "-" & $num & $ext
$num += 1
Until NOT FileExists($sharedFolder & "\" & $newFilename)
EndIf

FileCopy ($sourceFolder & "\" & $filename & $ext, $sharedFolder & "\" & $newFilename)
Thanks for this :) I modified it a bit more so here is the code. I can't seem to find a reason, why the 7zip archiver reports "Incorrect command"

when it should start packing up. I checked the code over and over again and i can't find that glitch. So once again, I'm asking for new check :)

Dim $sourceFolder = "C:\"
Dim $filename = @UserName & "." &  @MDAY & "." &  @MON & "." & @YEAR
Dim $ext = ".zip"
Dim $sharedFolder = "C:\Documents and settings\" & @UserName & "\Desktop\AICLogs"
Dim $destination1 = "\\ay-aic01\logs\TSDefinity_Voice1.log"
Dim $destination2 = "\\ay-aic02\logs\TSDefinity_Voice2.log"

RunWait ("C:\Program Files\7-zip\7z.exe a" & $sourceFolder & $filename & $ext & $destination1)

If FileExists($sharedFolder & "\" & $filename & $ext) Then
$num = 1
Do
$newFilename = $filename & "-" & $num & $ext
$num += 1
Until NOT FileExists($sharedFolder & "\" & $newFilename)
EndIf

RunWait ("C:\Program FIles\7-zip\7z.exe a" & $sourceFolder & $filename & $ext & $destination2)

If FileExists($sharedFolder & "\" & $filename & $ext) Then
$num = 1
Do
$newFilename = $filename & "-" & $num & $ext
$num += 1
Until NOT FileExists($sharedFolder & "\" & $newFilename)
EndIf

Share this post


Link to post
Share on other sites

You didn't check it very well, look at your RunWait():

RunWait ("C:\Program Files\7-zip\7z.exe a" & $sourceFolder & $filename & $ext & $destination1)

and then look at your original RunWait():

RunWait ( "7za.exe a -t7z -mx=9 " & $sourceFolder & $filename & $ext & " C:\Program Files\Someprogram\IC71\logs\*.log" )

The first one has the "a" attribute up against the source folder with no space, the second has no double quotes surrounding source and destination.

RunWait (@ProgramFilesDir & '\7-zip\7za.exe a -t7z -mx=9 "' & $sourceFolder & $filename & $ext & '" "C:\Program Files\Someprogram\IC71\logs\*.log"' )

Share this post


Link to post
Share on other sites

Hmm, now it's reporting that there's no such archive.

Dim $sourceFolder = "C:\"
Dim $filename = @UserName & "." &  @MDAY & "." &  @MON & "." & @YEAR
Dim $ext = ".zip"
Dim $sharedFolder = "C:\Documents and settings\" & @UserName & "\Desktop\AICLogs"

RunWait (@ProgramFilesDir & '\7-zip\7z.exe a "' & $sourceFolder & $filename & $ext & '" "\\ay-aic01\logs\TSDefinity_Voice1.log"' )

If FileExists($sharedFolder & "\" & $filename & $ext) Then
$num = 1
Do
$newFilename = $filename & "-" & $num & $ext
$num += 1
Until NOT FileExists($sharedFolder & "\" & $newFilename)
EndIf

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Well I tested this with a UNC path and it works fine for me:

Dim $sourceFolder = "C:\"
Dim $filename = @UserName & "." &  @MDAY & "." &  @MON & "." & @YEAR
Dim $ext = ".7z"

RunWait (@ProgramFilesDir & '\7-zip\7z.exe a -t7z "' & $sourceFolder & $filename & $ext & '" "\\test\www\*.log"' )
Edited by weaponx

Share this post


Link to post
Share on other sites

Well I tested this with a UNC path and it works fine for me:

Dim $sourceFolder = "C:\"
Dim $filename = @UserName & "." &  @MDAY & "." &  @MON & "." & @YEAR
Dim $ext = ".7z"

RunWait (@ProgramFilesDir & '\7-zip\7z.exe a -t7z "' & $sourceFolder & $filename & $ext & '" "\\test\www\*.log"' )
Thanks, it appears I have missed something :) It works now!

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Heh, bit more help needed. Your function

If FileExists($sharedFolder & "\" & $filename & $ext) Then
$num = 1
Do
$newFilename = $filename & "-" & $num & $ext
$num += 1
Until NOT FileExists($sharedFolder & "\" & $newFilename)
EndIf

doesn't include copying file to the folder... and since i'm such n00b at this, i ask again for your help :)

Edited by skysel

Share this post


Link to post
Share on other sites

Sure it does, you just didn't copy it:

#498556

Share this post


Link to post
Share on other sites

Sure it does, you just didn't copy it:

#498556

Bugger :) Now I get error message:

Supervisor.au3 (26) : ==> Variable used without being declared.:

FileCopy ($sourceFolder & "\" & $filename & $ext, $sharedFolder & "\" & $newFilename)

FileCopy ($sourceFolder & "\" & $filename & $ext, $sharedFolder & "\" & ^ ERROR

And complete code is:

Dim $sourceFolder = "C:\"
Dim $filename = "TSDefinity_Voice1_Log." &  @MDAY & "." &  @MON & "." & @YEAR
Dim $ext = ".7z"
Dim $sharedFolder = @UserProfileDir & "\Desktop\AICLogs"

FileCopy("\\ay-aic01\logs\TSDefinity_Voice1.log","C:\")
RunWait (@ProgramFilesDir & '\7-zip\7z.exe a -t7z "' & $sourceFolder & $filename & $ext & '" "C:\TSDefinity_Voice1.log"' )
FileDelete("C:\TSDEfinity_Voice1.log")


If FileExists($sharedFolder & "\" & $filename & $ext) Then
$num = 1
Do
$newFilename = $filename & "-" & $num & $ext
$num += 1
Until NOT FileExists($sharedFolder & "\" & $newFilename)
EndIf

FileCopy ($sourceFolder & "\" & $filename & $ext, $sharedFolder & "\" & $newFilename)

Share this post


Link to post
Share on other sites

Put this after the last Dim:

Dim $newFilename = $filename & $ext

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