Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rename file as (TODAY) 2

Status
Not open for further replies.

Majaws2

Programmer
Jul 3, 2003
15
0
0
US
I was trying to rename a file using aspect, so that the script does not overwrite or append to the existing file. Any ideas, I am currently using the below, but need to name file as a date string.

proc newname
string Fname = "C:\Program Files\symantec\Procomm Plus\Capture\testdump.cap"
string NewFName = "C:\Program Files\symantec\Procomm Plus\Capture\today.cap"

if not rename Fname NewFName
errormsg "Couldn't rename `"%s`" to `"%s`"." Fname NewFName
endif
endproc
 
Here is a script snippet that creates a filename in the format YYYYMMDD.TXT that you may find of use:

proc main
integer iDay, iMonth, iYear, iHour, iMin, iSec
string sFileName

ltimeints $LTIME iYear iMonth iDay iHour iMin iSec

strfmt sFileName "%d%02d%02d" iYear iMonth iDay
strcat sFileName ".TXT"
endproc

aspect@aspectscripting.com
 
I know the answer is in the knob thread, but I have zero programing experience. I don't know where to put the file name. Let me give you my example.

I have a file name test.txt that gets downloaded to the c:\ABC directory. The next day I will download the same file, but before that I want to rename the test.txt to test(date).txt and move it to c:\ABC\archive. How do I use the script above to do this? If you can create the script I would be most greatful. Thanks

 
Here's a script that copies the current file to the renamed file, then deletes the original file if the copy was successful.

proc main
integer iDay, iMonth, iYear, iHour, iMin, iSec
string sFileName
string sCurFile = "c:\ABC\test.txt"
string sNewFile = "c:\ABC\archive\"

ltimeints $LTIME iYear iMonth iDay iHour iMin iSec

strfmt sFileName "test%d%02d%02d.txt" iYear iMonth iDay
strcat sNewFile sFileName

if copyfile sCurFile sNewFile
delfile sCurFile
else
usermsg "Unable to copy current file!"
endif
endproc

aspect@aspectscripting.com
 
OK one more problem. The file that my system creates is arp370_1 (where the _1 gets incremented by 1 each time the file is created). So is there a way to use wildcards in an aspect file, or can I write a dos batch file that will copy the file arp370_1 to arp 370, and the call this file in the aspect script. Below is my curret script

proc main

dial data "cc"
while $dialing
yield
endwhile
if ! $carrier
statmsg "Connection attempt failed."
exit
endif

statmsg "Sending file to Paymentech"

set ascii timeout 40
pause 5
sendfile ascii "s:\arp370.txt"
while $xferstatus
yield
endwhile

getfile ascii "T:\download.txt"

;while $carrier
; yield
; endwhile

waitfor "EOFEOFEOF"
;if success
pause 5
hangup
;endif
endproc


THis script wont work, cause the file is not name apr370, but instead arp370_* (with star being the number that increments). Thanks again.
 
You could use the findfirst command to look for a file matching the pattern arp370_*.* in the directory you are interested in. This will find the first file that matches this pattern, whether it be arp370_1, arp370_2, etc. If there is more than one file matching this pattern, you could use findnext to find additional copies of this file.


aspect@aspectscripting.com
 
Knob, I know nothing about aspect programing, so I would not know how to use the findfirst command. Can you point me to somewhere that has syntext of all these commands. Or could you put in in my program above to give me an example.

Thanks
 
You can get the syntax on any ASPECT command by typing it in the ASPECT Editor (assuming that is what you use to write your scripts), then right click on the command. This will bring up the ASPECT help file with the discussion of that command.


aspect@aspectscripting.com
 
The ASPECT Editor is part of Procomm (Tools | Scripts | ASPECT Editor) or are you using a different editor to create your scripts?


aspect@aspectscripting.com
 
Ok as I see the help file below, what do I change in this program, so that it try to look for the file name, arp370_* (with * being the incrementing number).

proc main
string FileSpec = "*.*" ; File specifications to look for.
string Files[20] ; Array to hold file names.
integer Idx = 0 ; Index within file list array.

if findfirst FileSpec ; Find first file matching spec.
Files[Idx] = $FILENAME ; Set element of array to file name.
Idx += 1 ; Increment the array pointer.
while findnext ; Loop while still finding files.

Files[Idx] = $FILENAME ; Set element of array to file name.
Idx += 1 ; Increment the array pointer.
if Idx > 19 ; Exit loop if past size of array.
exitwhile
endif
endwhile
else
errormsg "No files found!"
endif
endproc
 
Will there be just one file matching arp370_* or can there be multiple files in that directory? The first step you would need to take would be to change the *.* in this line

string FileSpec = "*.*"

to point to where the arp370_* files are located, such as "c:\temp\arp370_*" The rest of the script would depend on your answer to the question above.


aspect@aspectscripting.com
 
No just one file, but it will increment by 1 each time it is run. The second problem may be is that they will possible run it a few times a day. Is I want to rename it with a date and place it in an archive folder, is there a way to keep arp370_*(plusedate) in the rename.
 
Here is a script that will search for for arp370*.txt in c:\temp (change the path in the FileSpec declaration to where the files are located), creates a new filename in the FileName variable, copies the old file to the new name (located in the path held by FilePath), then deletes the original file if the copy was successful. It's necessary to copy then delete the file since the renamed file and the original file are both found with the arp370*.txt search string.

proc main
string FileSpec = "c:\temp\arp370*.*" ; File specifications to look for.
string FileName
string FilePath = "c:\"

integer iDay, iMonth, iYear, iHour, iMin, iSec

if findfirst FileSpec ; Find first file matching spec.
ltimeints $LTIME iYear iMonth iDay iHour iMin iSec
strfmt FileName "%s%s%02d%02d%d.%s" FilePath $FNAME iMonth iDay iYear $FEXT
copyfile $FILESPEC FileName
if success
delfile $FILESPEC
endif
else
errormsg "No files found!"
endif
endproc

aspect@aspectscripting.com
 
OK, with all the info I have gather, I know I'm close. The final script needs to find the file in the arp370 folder. It will be called arp370_*. This file will increment by one each time. It will need to run it's process by uploading it's contance the after it is complete, it will run it's download process. Finally after this is down, the file (ex arp370_6 will need to be renamed arp370_6101302)(file name + date) and moved to the c:\arp370\archive folder.

proc main

dial data "cc"
while $dialing
yield
endwhile
if ! $carrier
statmsg "Connection attempt failed."
exit
endif

statmsg "Sending file to Paymentech"

set ascii timeout 40
pause 5
sendfile ascii "s:\arp370.txt"
while $xferstatus
yield
endwhile

getfile ascii "T:\download.txt"

;while $carrier
; yield
; endwhile

waitfor "EOFEOFEOF"
;if success
pause 5
hangup
;endif
endproc


Here is the script that works minus the renaming process. Only problem is the file is only caled arp370.txt once, the next time it is run it is called arp370_1 and so on.


Hope i'm not being to much of a pain. Thanks again.

Mike
 
Pasting together your script and my script I came up with this, which should be pretty close to what you are wanting:

proc main
string FileSpec = "s:\arp370*.*" ; File specifications to look for.
string FileName
string FilePath = "c:\arp370\archive\"
integer iDay, iMonth, iYear, iHour, iMin, iSec

dial data "cc"
while $dialing
yield
endwhile
if ! $carrier
statmsg "Connection attempt failed."
exit
endif

statmsg "Sending file to Paymentech"

set ascii timeout 40
pause 5
if findfirst FileSpec ; Find first file matching spec.
sendfile ascii "s:\arp370.txt"
while $xferstatus
yield
endwhile

getfile ascii "T:\download.txt"
while $xferstatus
yield
endwhile

ltimeints $LTIME iYear iMonth iDay iHour iMin iSec
strfmt FileName "%s%s%02d%02d%d.%s" FilePath $FNAME iMonth iDay iYear $FEXT
copyfile $FILESPEC FileName
if success
delfile $FILESPEC
endif

;while $carrier
; yield
; endwhile

waitfor "EOFEOFEOF"
;if success
pause 5
hangup
;endif
else
errormsg "No files found!"
endif
endproc


aspect@aspectscripting.com
 
I'm not sure if I follow the flow, be here goes.


What needs to be done 1st is
1-run a process that creates the file arp370_*
2-Find this file and upload it to another server.
3-Take this file and remane it to arp370_*(plus date)
4-move file to archive directory.

If I am correct, It looks like the file is being renamed 1st, am I wrong?

Can you explain the flow? Thanks
 
What the script I posted does is dial the &quot;cc&quot; entry in the Connection Directory, searches for arp370*.* in s:\, uploads it if found, and then downloads another file to t:\download.txt. The script then copies the file to c:\arp370\archive\<filename>MMDDYYYY.txt and deletes the original file it downloaded. I found one small problem in the script (was not trying to upload the correct file), here is the updated version:

proc main
string FileSpec = &quot;s:\arp370*.*&quot; ; File specifications to look for.
string FileName
string FilePath = &quot;c:\arp370\archive\&quot;
integer iDay, iMonth, iYear, iHour, iMin, iSec

dial data &quot;cc&quot;
while $dialing
yield
endwhile
if ! $carrier
statmsg &quot;Connection attempt failed.&quot;
exit
endif

statmsg &quot;Sending file to Paymentech&quot;

set ascii timeout 40
pause 5
if findfirst FileSpec ; Find first file matching spec.
sendfile ascii FileSpec
while $xferstatus
yield
endwhile

getfile ascii &quot;T:\download.txt&quot;
while $xferstatus
yield
endwhile

ltimeints $LTIME iYear iMonth iDay iHour iMin iSec
strfmt FileName &quot;%s%s%02d%02d%d.%s&quot; FilePath $FNAME iMonth iDay iYear $FEXT
copyfile $FILESPEC FileName
if success
delfile $FILESPEC
endif

;while $carrier
; yield
; endwhile

waitfor &quot;EOFEOFEOF&quot;
;if success
pause 5
hangup
;endif
else
errormsg &quot;No files found!&quot;
endif
endproc

aspect@aspectscripting.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top