I use XY - a lot - but recently I have a need for a very small copy (Only) job that does the following:
1. Copies specific file types (*.wav in this case) from an ever growing series of multi level folders tree like so:
M:\Client A\12-2015\12-03-2015\
M:\Client B\12-2015\12-03-2015\
M:\Client C\12-2015\12-04-2015\
M:\Client D\12-2015\12-05-2015\
to a destination folder named M:\Client Files resulting in something like this:
M:\Client Files\12-2015\12-03-2015\
M:\Client Files\12-2015\12-03-2015\
M:\Client Files\12-2015\12-04-2015\
M:\Client Files\12-2015\12-05-2015\
Basically copy 4 parent folders (and ALL their sub directories) and create the same 4 folder trees (AND all sub directories) over in the Client Files directory.
2. Copies ONLY those wav files that were created within a very small defined time range (<2 hours)
3. Can be run on demand? Script?
NOTE: This is a straight copy job. Another application process is "watching" the Client Files folder - and whenever it sees a wav file appear in there - instantly converts the .wav file to MP3 and moves the incoming files (and the entire copied folder structure) to another folder.
Would it be possible for XY to tackle this via scripting? if so - what would be the best way to set it up and run it?
This is what I have in Robocopy right now:
robocopy "M:\CLIENT - A" "M:\Client Files\CLIENT - A" *.wav /E /MAXAGE:1
robocopy "M:\CLIENT - B" "M:\Client Files\CLIENT - B" *.wav /E /MAXAGE:1
robocopy "M:\CLIENT - C" "M:\Client Files\CLIENT - C" *.wav /E /MAXAGE:1
robocopy "M:\CLIENT - D" "M:\Client Files\CLIENT - D" *.wav /E /MAXAGE:1
Except it does not provide the granularity for me to just copy wav files created in the last 2 hours. Best this will do is wav files no older than a 1 day (too old for my purpose). Robocopy does not allow me to specify hours with the MAXAGE switch.
Appreciate your take on this...
Cheers!
VP
Script to copy specific files created in last x mins or hrs?
-
- Posts: 163
- Joined: 06 Nov 2009 14:01
Re: Script to copy specific files created in last x mins or
TEST THE SCRIPT FIRST WITH SOME TEST FILES.
should be equivalent to the robocopy batch script.
TODO Elaborate solution
Code: Select all
::$sources= "M:\Client A\;M:\Client B;M:\Client C;M:\Client D"; copyto "M:\Client Files\", quicksearch('*.wav AND ageC: <= 2 h', $sources, '|'), 'M:\';
TODO Elaborate solution
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
Re: Script to copy specific files created in last x mins or
copies all <=2hr old M:\Client *\dirs\*wav to M:\Client Files\dirs\*.wav
can continue running for a few loops. (by default runs once every hour for 10 hours)
can continue running for a few loops. (by default runs once every hour for 10 hours)
Code: Select all
"Elaborate Copy Job"
$frequency = 1000*60*60*1; //every 1 hour
$repeats = 10; //how many times to loop (will run for $frequency*$repeats length of time)
while ($repeats > 0){
// msg "restrating ".self('caption');
// >> if you don't want the looping feature, use the part of the script upto the next comment
$root = 'M:';
$target = $root . '\Client Files';
$sources = quicksearch('>^Client\s(?!Files|Accounts) /dn', $root, '|'); //finds all `client *` folders minus `Client Files`, `Client Accounts` (you get the idea)
$files = quicksearch('*.wav AND ageC: <= 2 h', $sources, '|'); //find all <=2hr old *.wav files in source paths
setting 'BackgroundFileOps', 0;
foreach ($file, $files) {
//copyto $target.replacelist(getpathcomponent($file, 'path'), $sources, '', '|'), $file,, 2;
$location = $target.replacelist(getpathcomponent($file, 'path'), $sources, '', '|');
if (exists($location) != 2) {$location = new($location, 'dir');}
backupto $location, $file, 2, 1, 0, 0, 0, 0, 0;
// delete 0, 0, $file; uncomment this line to effectively move files
}
// >> if you don't want the looping feature, use the part of the script upto here
$repeats--;
wait $frequency;
}
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
Re: Script to copy specific files created in last x mins or
@ SammaySarkar
Blocking the possibility of executing other xyplorer scripts for hours just to execute a "simple" copy job (that can be externalized with almost all scripting languages)? If we had multithreading, ok...
Blocking the possibility of executing other xyplorer scripts for hours just to execute a "simple" copy job (that can be externalized with almost all scripting languages)? If we had multithreading, ok...
One of my scripts helped you out? Please donate via Paypal
Re: Script to copy specific files created in last x mins or
. yeeah, or vocalpoint can just keep a unused instance of XYplorer running with this job.
edit: moved tangential posts to http://www.xyplorer.com/xyfc/viewtopic.php?f=3&t=15145
edit: moved tangential posts to http://www.xyplorer.com/xyfc/viewtopic.php?f=3&t=15145
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
-
- Posts: 163
- Joined: 06 Nov 2009 14:01
Re: Script to copy specific files created in last x mins or
Sammay,
Thanks for the suggestions! Lots of good stuff here - but I just require a simple command to be run on demand. No looping or extra copies of XY running in the back ground etc.
I will give the single line option a try.
Cheers!
VP
Thanks for the suggestions! Lots of good stuff here - but I just require a simple command to be run on demand. No looping or extra copies of XY running in the back ground etc.
I will give the single line option a try.
Cheers!
VP
Re: Script to copy specific files created in last x mins or
did you look at the second script? you can use this portion too, skipping the looping.
Code: Select all
$root = 'M:';
$target = $root . '\Client Files';
$sources = quicksearch('>^Client\s(?!Files|Accounts) /dn', $root, '|'); //finds all `client *` folders minus `Client Files`, `Client Accounts` (you get the idea)
$files = quicksearch('*.wav AND ageC: <= 2 h', $sources, '|'); //find all <=2hr old *.wav files in source paths
setting 'BackgroundFileOps', 0;
foreach ($file, $files) {
//copyto $target.replacelist(getpathcomponent($file, 'path'), $sources, '', '|'), $file,, 2;
$location = $target.replacelist(getpathcomponent($file, 'path'), $sources, '', '|');
if (exists($location) != 2) {$location = new($location, 'dir');}
backupto $location, $file, 2, 1, 0, 0, 0, 0, 0;
// delete 0, 0, $file; uncomment this line to effectively move files
}
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
-
- Posts: 163
- Joined: 06 Nov 2009 14:01
Re: Script to copy specific files created in last x mins or
I did - but it seems a bit restrictive in that you are "looking" for folders with the word "client" in them - as I could easily need to add other folders with other names to the layout - how would this piece handle 10 folders all with different names?SammaySarkar wrote:did you look at the second script? you can use this portion too, skipping the looping.Code: Select all
$root = 'M:'; $target = $root . '\Client Files'; $sources = quicksearch('>^Client\s(?!Files|Accounts) /dn', $root, '|'); //finds all `client *` folders minus `Client Files`, `Client Accounts` (you get the idea) $files = quicksearch('*.wav AND ageC: <= 2 h', $sources, '|'); //find all <=2hr old *.wav files in source paths setting 'BackgroundFileOps', 0; foreach ($file, $files) { //copyto $target.replacelist(getpathcomponent($file, 'path'), $sources, '', '|'), $file,, 2; $location = $target.replacelist(getpathcomponent($file, 'path'), $sources, '', '|'); if (exists($location) != 2) {$location = new($location, 'dir');} backupto $location, $file, 2, 1, 0, 0, 0, 0, 0; // delete 0, 0, $file; uncomment this line to effectively move files }
I like this one a lot but would need help in naming exact locations for the script to look into to find wav files.
Cheers!
VP
Re: Script to copy specific files created in last x mins or
Here's another version. First you have to select all the source folders in list. Then run the script.
Code: Select all
$root = 'M:';
$target = $root . '\Client Files';
//$sources = quicksearch('>^Client\s(?!Files|Accounts) /dn', $root, '|'); //finds all `client *` folders minus `Client Files`, `Client Accounts` (you get the idea)
$sources = '';
foreach($itm, <get 'selecteditemspathnames' '|'>){
if (exists($itm) == 2){$sources = $sources.'|'.$itm;}
}
$sources = trim($sources, '|', 'L');
end (gettoken($sources, 'count', '|')==0); //end if no folders selected
$files = quicksearch('*.wav AND ageC: <= 2 h', $sources, '|'); //find all <=2hr old *.wav files in source paths
setting 'BackgroundFileOps', 0;
foreach ($file, $files) {
//copyto $target.replacelist(getpathcomponent($file, 'path'), $sources, '', '|'), $file,, 2;
//backupto can't auto-create target folders, workaround
$location = $target.replacelist(getpathcomponent($file, 'path'), $sources, '', '|');
if (exists($location) != 2) {$location = new($location, 'dir');}
backupto $location, $file, 2, 1, 0, 0, 0, 0, 0;
// delete 0, 0, $file; uncomment this line to effectively move files
}
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
-
- Posts: 163
- Joined: 06 Nov 2009 14:01
Re: Script to copy specific files created in last x mins or
Wow. Will try it out.SammaySarkar wrote:Here's another version. First you have to select all the source folders in list. Then run the script.
Cheers!
VP