Jump to content

[Resolved] Modifying this to include only certain file types?


Recommended Posts

I have had great help in the past and now make my "backup" scripts using the type of syntax below as it works very well for me. But in the past it's been necessary to back up the entire contents of the folder so this worked. In this present case, just need to copy the files with extension .DRY. Here is the script to modify, which I don't know how to add the additional .dry filter to:

$SamePartition = StringLeft(@ScriptDir, 2)     ; sets folder path's variable so that script uses relative vs. absolute paths

$sourceFolder = $SamePartition & "\DIARY\Diary v4.12\APP- Diary v4.12"
$destinationFolder = $SamePartition & "\DIARY\Diary v4.12\BKP- Diary v4.12\Diary v4.12 files, BKP- "
$destinationFolder &= @YEAR & "." & @MON & "." & @MDAY & ", " & @HOUR & "h" & @MIN & "m" & @SEC & "s"
DirCopy($sourceFolder, $destinationFolder, 8)

Sleep(100)
Send("{F5}")

Exit     ; finished

Thanks so much! :)

Edited by Diana (Cda)
Link to comment
Share on other sites

I have had great help in the past and now make my "backup" scripts using the type of syntax below as it works very well for me. But in the past it's been necessary to back up the entire contents of the folder so this worked. In this present case, just need to copy the files with extension .DRY. Here is the script to modify, which I don't know how to add the additional .dry filter to:

$SamePartition = StringLeft(@ScriptDir, 2)     ; sets folder path's variable so that script uses relative vs. absolute paths

$sourceFolder = $SamePartition & "\DIARY\Diary v4.12\APP- Diary v4.12"
$destinationFolder = $SamePartition & "\DIARY\Diary v4.12\BKP- Diary v4.12\Diary v4.12 files, BKP- "
$destinationFolder &= @YEAR & "." & @MON & "." & @MDAY & ", " & @HOUR & "h" & @MIN & "m" & @SEC & "s"
DirCopy($sourceFolder, $destinationFolder, 8)

Sleep(100)
Send("{F5}")

Exit     ; finished

Thanks so much! :)

The flag for DirCopy can be 0 or 1 so 8 looks like an error.

Are there subfolders in the folder to be copied?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

The flag for DirCopy can be 0 or 1 so 8 looks like an error.

Are there subfolders in the folder to be copied?

Oh, yes. Forgot about that. Sorry. No, it's not an error; I copy-paste when doing up new scripts <g>. As I remember, in the other scripts I've used this for the subfolders were copied so 8 was needed. The problem in this new situation is different. Here I don't need all the files in the folders backed up, only a group of files with a certain extension. But the only syntax I know to do this type of thing is actually for a specific file only, not a bunch of files with the same extension. Here is the pertinent syntax for that:
$file = @ScriptDir & "\twc.ses"
$fileDir = Stringleft($file, StringInStr($file, "\", 0, -1) - 1)    ; ALL up to (but not including) the last backslash
$fileName = StringRight($file, StringLen($file) - StringInStr($file, "\", 0, -1))   ; what's left after last backslash
;$file2 = $fileDir & "\" & "zBKP- " & $fileName & " - " & @YEAR & "." & @MON & "." & @MDAY & ", " & @HOUR & "h" & @MIN & ".ses"
$file2 = $fileDir & "\" & "zBKP- " & $fileName & " - " & @YEAR & "." & @MON & "." & @MDAY & ", " & @HOUR & "h" & @MIN & "m" & @SEC & "s" & ".ses"
FileCopy($file, $file2)

I just don't know how to do copy all files of a certain extension. That's why I provided the syntax I did know in the original message at the top of htis thread.

What can be done? Thx. :)

Link to comment
Share on other sites

Oh, yes. Forgot about that. Sorry. No, it's not an error; I copy-paste when doing up new scripts <g>. As I remember, in the other scripts I've used this for the subfolders were copied so 8 was needed. The problem in this new situation is different. Here I don't need all the files in the folders backed up, only a group of files with a certain extension. But the only syntax I know to do this type of thing is actually for a specific file only, not a bunch of files with the same extension. Here is the pertinent syntax for that:

$file = @ScriptDir & "\twc.ses"
$fileDir = Stringleft($file, StringInStr($file, "\", 0, -1) - 1)    ; ALL up to (but not including) the last backslash
$fileName = StringRight($file, StringLen($file) - StringInStr($file, "\", 0, -1))   ; what's left after last backslash
;$file2 = $fileDir & "\" & "zBKP- " & $fileName & " - " & @YEAR & "." & @MON & "." & @MDAY & ", " & @HOUR & "h" & @MIN & ".ses"
$file2 = $fileDir & "\" & "zBKP- " & $fileName & " - " & @YEAR & "." & @MON & "." & @MDAY & ", " & @HOUR & "h" & @MIN & "m" & @SEC & "s" & ".ses"
FileCopy($file, $file2)

I just don't know how to do copy all files of a certain extension. That's why I provided the syntax I did know in the original message at the top of htis thread.

What can be done? Thx. :)

I think you only need to look up FileFindFirstFile and FileFindNextFile.

I'm not sure about the flag in DirCopy; I think that you're thinking of FileCopy.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I think you only need to look up FileFindFirstFile and FileFindNextFile.

I'm not sure about the flag in DirCopy; I think that you're thinking of FileCopy.

Thanks! I looked at FileCopy once more. I hadn't gotten it to work before in this specialized type of situation. I have this now:
$SamePartition = StringLeft(@ScriptDir, 2)     ; sets folder path's variable so that script uses relative vs. absolute paths

$sourceFolder = $SamePartition & "\DIARY\Diary v4.12\APP- Diary v4.12"
$destinationFolder = $SamePartition & "\DIARY\Diary v4.12\BKP- Diary v4.12\Diary v4.12 files, BKP- "
$destinationFolder &= @YEAR & "." & @MON & "." & @MDAY & ", " & @HOUR & "h" & @MIN & "m" & @SEC & "s"
FileCopy($sourceFolder & "\*.dry", $destinationFolder & "\*.dry", 8)

Sleep(100)
Send("{F5}")

Exit     ; finished
This seems to do the job. I get to use relative paths, I get a time-stamped folder and its contents are only the data files needed to be backed up. Awesome! Now I have an easy to use and maintain journal program to keep track of employment issues.

Days like this encourage to have hope that one day I'll script in AutoIt virtually all on my own!!! <vbg>

Thanks! :)

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