Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Copy most recent file
#1
I have a folder of backups, and I need to always copy the most recent file. The files are named like this:
tenant_data_backup_2015_09_21_060001_9730201.bak

Is there any way I can always get the most recent file in the folder?
#2
Function GetMostRecentFileInFolder
Code:
Copy      Help
;/
function# str&filePath $folder [$filenamePattern] [flags] [flags2] [DateTime&getTime] ;;flags: 0 files, 1 folders, 2 any, 4 +subfolders, 8 only subfolders, 32 skip symbolic-link subfolders, 64 skip hidden-system, 0x10000 regular expression, 0x20000 compare relative path.

;Gets full path of the newest (most recently modified) or oldest file in a folder.
;Returns the number of matching files in the folder.

;filePath - variable that receives file path.
;folder - folder where to look for files.
;filenamePattern - if used and not "", looks for files that match filenamePattern. Else looks for all files.
;;;Can be filename with <help #IDP_WILDCARD>wildcard characters</help> (*?), or regular expression (flag 0x10000).
;;;Can be relative path (flag 0x20000).
;flags - same as with <help>GetFilesInFolder</help>.
;flags2: 1 get the oldest file.
;getTime - optional variable that receives file time, UTF.

;REMARKS
;Uses <help>GetFilesInFolder</help>. Parameters folder, filenamePattern and flags are the same.

;EXAMPLES
;str sPath
;if GetMostRecentFileInFolder(sPath "$documents$")
,;out F"newest file:  {sPath}"
;
;DateTime t
;str sPath2
;if GetMostRecentFileInFolder(sPath2 "$documents$" "" 0 1 t)
,;out F"oldest file:  {sPath2}  ({t.ToStr(4)})"


opt noerrorshere 1
ARRAY(str) a
GetFilesInFolder a folder filenamePattern flags 2
if(!a.len) filePath.all; ret
a.sort(iif(flags2&1 8 9))
DateTime t=val(a[0] 1 _i) ;;use DateTime for times. Use long for size.
if(&getTime) getTime=t
filePath=a[0]+_i+1
ret a.len
#3
Thanks for that, but, I don't understand how to use that with a specific window.

For example, here is what I am trying to do (simple example):

Code:
Copy      Help
int w=win("162.xxx.xxx.xx - Remote Desktop Connection" "TscShellContainerClass")

act w

str sPath = "E:\MSSQL\Backup\tenant_data"

if GetMostRecentFileInFolder(sPath "$documents$")
    out F"newest file: {sPath}"

Thanks in advance.
#4
Okay, I guess it is not possible. Seems to me it should be a common thing to automate, but I can find no example of how to do it with QM, or on this forum.

I will look at other options. Thanks.
#5
I will try creating a self-executing macro that does the copying from one drive to the other on the remote server, and try launching that with the RUN command, since that seems to be able to use a target window. Hopefully that will allow me to open the remote desktop connection window (which is working fine) and then run the copy macro to transfer the most recent file in the folder from the one drive to the other.
#6
If you want to start the copy-files program from your computer to run on remote computer, I don't know is it possible directly/easily, but here are 3 ideas, not tested:

On remote computer create a shortcut to run the copy-files program. Maybe in Start menu, or on desktop. Set a hotkey for the shortcut. Then on my computer run macro that sends the hotkey to the Remote Desktop window.

On remote computer install QM and allow to run macros there from other computers. On my computer run macro that uses function net to run the remote macro that copies files there. If don't want to install QM there, it is possible to create exe that uses TCP...

Try PsExec, it seems it can run programs on other computers:
https://technet.microsoft.com/en-us/sys ... 97553.aspx


Forum Jump:


Users browsing this thread: 2 Guest(s)