Sign in to follow this  
Followers 0
Myke

File copy and naming

10 posts in this topic

Hello,

I am new to Autoit and Im not sure where to start.

I have a project that I have been working on that I need a little help with. I have a piece of software that writes log files to a directory on the C Drive. It names the files for the day of the month that the file is created.

For example log01.txt, log02.txt, log03.txt ..... log29.txt, log30.txt

It does this through the end of the month. Then it starts over again and overwrites the previous month. We need to keep these records for historical data.

What I need to do is first check to see if a folder exists on a networked drive that corresponds with the year, then a subfolder for month then a subfolder using the computername. If those folders do not exist then create them. Then I need to place the log file for that particular day inside the corresponding folder on the networked drive.

Any help would be appreciated.

Share this post


Link to post
Share on other sites



You may find the following commands in the help file of use:

FileFindFirstFile - find the first file in a folder matching (can use wildcards such as log*.txt in your case)

FileFindNextFile - find next one

FileGetTime - to extract the date information for a file

FileMove - moves and renames files

@ComputerName - Computer's network name

@MDAY - day of month

@YEAR - four digit year

Suggestion: For sorting purposes, can I recommend YYYYMMDD for your date storage

Good luck!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You may find the following commands in the help file of use:

FileFindFirstFile - find the first file in a folder matching (can use wildcards such as log*.txt in your case)

FileFindNextFile - find next one

FileGetTime - to extract the date information for a file

FileMove - moves and renames files

@ComputerName - Computer's network name

@MDAY - day of month

@YEAR - four digit year

Suggestion: For sorting purposes, can I recommend YYYYMMDD for your date storage

Good luck!

and dont' forget

FileExists()

_FileWriteLog()

FileCopy()/FileMove() ; whether you want to keep a copy on the C:\ or move the file to the network share

DirCreate()

DirCopy()

***edit***

i didn't explain each function because the names seemed kind of self explanatory and full details and examples for each are in the help file

Edited by cameronsdad

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Im having issues creating a new folder on the mapped drive. This works ok on my computer but it wont create a directory on the server. Are there any known issues with creating a directory on Novell servers?

$answer = MsgBox(4, "Data Backup", "This Script will backup the Data. Continue?")

If $answer = 7 Then
    MsgBox(0, "Quit", "Remember to backup your data!")
    Exit
EndIf

If FileExists("Z:\"&@YEAR&"\month"&@MON&"\"&@ComputerName&"\") Then
    FileCopy("C:\Program Files\APPfolder\Log\log"&@MDAY&".*","Z:\"&@YEAR&"\month"&@MON&"\"&@ComputerName&"\*.*")
Else
    DirCreate("Z:\"&@YEAR&"\month"&@MON&"\"&@ComputerName&"\")
    FileCopy("C:\Program Files\APPfolder\Log\log"&@MDAY&".*","Z:\"&@YEAR&"\month"&@MON&"\"&@ComputerName&"\*.*")
    EndIf
Thanks for everyones help. Edited by Myke

Share this post


Link to post
Share on other sites

Well I found out how to post code in a separate window.

Share this post


Link to post
Share on other sites

Well I found out how to post code in a separate window.
step 2 is to find out how to edit a post.... ;) just giving you a hard time there.

the script provided worked fine on my computer after a couple of little changes, purely aesthetic though...

make sure that the user running the program has permissions to create directories on the shared drive, if not, you're going to have to use RunAsSet() to run your compiled script from another script, or setup your script to run as a different user with permissions to do what you want. here's my code...

$answer = MsgBox(4, "Data Backup", "This Script will backup the Data. Continue?")

If $answer = 7 Then
MsgBox(0, "Quit", "Remember to backup your data!")
Exit
EndIf
$mapped = "Z:\"&@YEAR&"\month"&@MON&"\"&@ComputerName&"\"
$local = "C:\"&@YEAR&"\month"&@MON&"\"&@ComputerName&"\"
If FileExists($mapped) Then
FileCopy($local & "*.*", $mapped)
Else
DirCreate($mapped)
FileCopy($local & "*.*",$mapped)
EndIf

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

step 2 is to find out how to edit a post.... just giving you a hard time there.

:"> Yeah.... I figured that one out too.

Thanks for the tip on setting up the Var in the script.

Ok.. heres the thing. I have full Admin rights to the Novell servers. When I tried to run the script with $mapped set to my Z: drive it did not create the directory. This was a Novell Server.

$mapped = "Z:\test1\"&@YEAR&"\month"&@MON&"\"&@ComputerName&"\"
$local = "C:\test\"


If FileExists($mapped) Then
FileCopy($local & "\log" & @MDAY & ".txt",$mapped & "\*.*")
Else
DirCreate($mapped)
FileCopy($local & "\log" & @MDAY & ".txt",$mapped & "\*.*")
EndIf

When I ran the script with the W: drive mapped it created the directory. The W: drive is mapped to a windows 2003 server.

$mapped = "W:\test1\"&@YEAR&"\month"&@MON&"\"&@ComputerName&"\"
$local = "C:\test\"


If FileExists($mapped) Then
FileCopy($local & "\log" & @MDAY & ".txt",$mapped & "\*.*")
Else
DirCreate($mapped)
FileCopy($local & "\log" & @MDAY & ".txt",$mapped & "\*.*")
EndIf

The only difference was the drive letter and of course the type of server.

Has anyone ever seen this before?

Thanks again for your help.

Share this post


Link to post
Share on other sites

The only difference was the drive letter and of course the type of server.

Has anyone ever seen this before?

Thanks again for your help.

add the following code to your script right AFTER DirCreate() and post the results (content of the clipboard).

$lastError = DllCall("kernel32.dll", "int", "GetLastError")

ClipPut("Error: " & $lastError[0])

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

The content of the clipboard was:

Error: 3

Is there a place to lookup error codes?

This one doesn't seem very helpful........

Edited by Myke

Share this post


Link to post
Share on other sites

The content of the clipboard was:

Error: 3

Is there a place to lookup error codes?

This one doesn't seem very helpful........

According to the error code list HERE, the system was not able to find the path. Try to map your novell file share to another drive letter.

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

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