How can I copy a file that always changes file name?

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
despinal
Newbie
Posts: 16
Joined: Tue Jul 26, 2005 4:49 pm
Location: New York

How can I copy a file that always changes file name?

Post by despinal » Mon Dec 04, 2006 2:29 pm

Guys,

I'm looking to copy a file from one location to another. It's a WAV file that gets generated when using Cain & able when sniffing voip calls made from a system that automatically dials out a conference call.

The idea behind this is to make a copy of this file which its never the same name to a different path with a specific name.

Can anyone tell me what would be the best way to do this? vbscript or batch file?

Thanks,

Dannye

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Mon Dec 04, 2006 7:08 pm

If the file size is always the same you could use GetFileList>c:\temp\*.wav,files to list the WAV files, then use FileSize> to find the file you're looking for.

Examples are in the help file ;)

GetFileList> example

Code: Select all

GetFileList>filespec,result[,delimiter]

GetFileList returns a list of the files found matching the specified filespec.  For instance, to return the list of files in the temp directory specify c:\temp\*.* as the filespec.

If delimiter is ommitted each filename is separated by a semicolon (;).  Otherwise the filenames are separated by the delimiter specified.

Abbreviation : GFL

Example

GetFileList>c:\temp\*.*,files

Separate>files,;,file_names

MessageModal>Num Files: %file_names_count%

 

Let>k=0

Repeat>k

               Let>k=k+1

               Message>file_names_%k%

Until>k,file_names_count

FileSize> Example

Code: Select all

FileSize>filename,result

Returns the size of filename in the result variable.

The size is returned in bytes.

filename can include a full path.

Abbreviation : FSZ

See also : FileDate

Example

FileSize>c:\program files\myfile.exe,MyFileSize

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Dec 04, 2006 7:20 pm

What I would do is use GetFileList and store the result in an INI file. Each time compare the result with what was stored. That would tell me which file(s) is/are new. I then know which file to copy.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Dec 04, 2006 7:21 pm

Or just look for the newest file in the directory. Examples to do that are on this forum.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

despinal
Newbie
Posts: 16
Joined: Tue Jul 26, 2005 4:49 pm
Location: New York

Post by despinal » Wed Dec 06, 2006 3:36 pm

mtettmar wrote:Or just look for the newest file in the directory. Examples to do that are on this forum.
Hey MTETTMAR, this would definitely work for me... I tried searching for such examples, but didn't find anything. Can you please help on this? thanks again

Dannye

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Dec 06, 2006 8:41 pm

Here is one example.

despinal
Newbie
Posts: 16
Joined: Tue Jul 26, 2005 4:49 pm
Location: New York

Post by despinal » Wed Dec 06, 2006 9:06 pm

JRL wrote:Here is one example.
Thanks for the reply JRL...

I'm more than a newbie, so please bare with me on this... I used your sample and I'm sure I'm using it the wrong way. Can you please correct it for me?
-----
Run>cmd /c dir [C]:\[Program Files\Cain\VoIP] /o-d /b > [C]:\[Archive]\[list.txt]
ReadLn>[C]:\[Archive]\[list.txt],1,NewestFile
-----

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Dec 06, 2006 9:10 pm

despinal wrote:
mtettmar wrote:Or just look for the newest file in the directory. Examples to do that are on this forum.
Hey MTETTMAR, this would definitely work for me... I tried searching for such examples, but didn't find anything. Can you please help on this? thanks again

Dannye
Take a look at:

http://www.mjtnet.com/forum/viewtopic.php?t=3073

http://www.mjtnet.com/forum/viewtopic.php?t=1462
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Dec 06, 2006 9:24 pm

//RP_WAIT causes the script to pause until the external task completes
Let>RP_WAIT=1

//This is doing a dir in a DOS window. Set RP_WINDOWMODE=0 to not see
//the DOS window
Let>RP_WINDOWMODE=1

//You did not want the braces, they were there as standard nomenclature.
//DOS requires quotes around any location with spaces in the name.
//This will create a file "C:\Archive\list.txt" that is a list of all of the files
//at location "C:\[Program Files\Cain\VoIP". The list is sorted in descending
//date/time order
Run>cmd /c dir "C:\[Program Files\Cain\VoIP" /o-d /b > C:\Archive\list.txt

//This next line will set the variable "NewestFile" to the name of the newest
//file in the list that is file "C:\Archive\list.txt"
ReadLn>C:\Archive\list.txt,1,NewestFile

// The path and file name are now:
//C:\[Program Files\Cain\VoIP\%NewestFile%
// you can display this using MessageModal>
MessageModal>Newest file = C:\[Program Files\Cain\VoIP\%NewestFile%

despinal
Newbie
Posts: 16
Joined: Tue Jul 26, 2005 4:49 pm
Location: New York

Post by despinal » Wed Dec 06, 2006 9:50 pm

Thanks JRL... that did the trick and it's really simple...

....................
Let>RP_WAIT=1
Let>RP_WINDOWMODE=1
Run>cmd /c dir "C:\Program Files\Cain\VoIP" /o-d /b > C:\Archive\list.txt
ReadLn>C:\Archive\list.txt,1,NewestFile
MessageModal>Newest file = C:\Program Files\Cain\VoIP\%NewestFile%
....................

My last request: instead of showing me the "MessageModal" what command can I use to copy the newest file to another location? (example: C:\Archived)

By the way... where can I send you a donation to? :)

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Dec 06, 2006 10:01 pm

Straight out of the help for Macro Scheduler:
CopyFile>sourcefile,destinationfile

Copies the file (or files), sourcefile, to destinationfile

Sourcefile, and destinationfile may be variables. Wildcards can be used.

By default if destinationfile already exists it will not be overwritten and the new file will be renamed appropriately. It is possible to change the bahaviour of the CopyFile command to overwrite instead by setting CF_OVERWRITE to 1. The default value of CF_OVERWRITE is 0.

Abbreviation : Cop

See also : MoveFile, DeleteFile, IfFileExists, AppendFile, RenameFile

Example

CopyFile>c:\temp\myfile.txt,c:\my documents\myfile.old

Or with variables:

Let>filename=c:\temp\myfile.txt
Let>newfilename=c:\temp\myfile.new
CopyFile>filename,newfilename
Your line might be:
CopyFile>C:\Program Files\Cain\VoIP\%NewestFile%,C:\Archived

despinal
Newbie
Posts: 16
Joined: Tue Jul 26, 2005 4:49 pm
Location: New York

Post by despinal » Thu Dec 07, 2006 12:38 pm

JRL wrote:Straight out of the help for Macro Scheduler:
CopyFile>sourcefile,destinationfile
Perfect!

You're a genius!

Huge thanks!

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts