| |
|
Welcome to KnowledgeSutra - Dear Guest | |
Copy A File And Rename It With Increment If Exist
#2
Posted 08 September 2008 - 02:43 PM
#3
Posted 09 September 2008 - 07:02 AM
pasten, on Sep 8 2008, 02:43 PM, said:
Thanks for your reply, but its not what i am looking for. I just want a vbscript wich does only kopie a specified file xx times and name it to:
[any name]1, [any name]2, [any name]3 etc etc.
I already know how to copy a file one time but thats it.
#4
Posted 09 September 2008 - 08:27 AM
An illustration of the concept would be for a backup of your mySQL database, for instance. Lets say you have a CRON job that will create an automated backup of your mySQL database, that puts the resulting database in the same place all the time, overwriting the previous backup with the same name, to save on storage space. But you want to keep multiple versions of the backups on your local computer, so you want a script that will copy the source file from the original backup on the server at, say, ftp://ftp.mysite.tra...atestbackup.zip and then put it on your local computer, say, at c:\my documents\backups\*.zip but name it incrementally one higher than the previous existing backup. Does that sound like the type of thing that you are after?
Let me see if I can put it into a logical flow for you. The code below is not written in any particular programming language and will not compile in its current form, this is just for the sake of clarification of the logic flow....
'**** Declare Variables **** DIM sourcepath$ AS String 'The path to the source file, includes backslash DIM sourcefile$ AS String 'The name of the source file without a loop number DIM destpath$ AS String 'The path to the destination file, includes backslash DIM max AS Integer 'The maximum number of copies to keep DIM a AS Integer 'A loop counter '**** Main Loop **** FOR a = max-1 TO 1 'Create a decreasing loop counter IF EXIST destpath$ & sourcefile$ & a THEN 'If the filename with current counter's value exists..... COPY (sourcepath$ & sourcefile$, destpath$ & sourcefile$ & a+1) 'Copy the file adding the loop counter + 1 END NEXT 'Break out of the FOR-NEXT loop now END IF NEXT a 'Otherwise, decrement the loop counter by one and try again.Sure, there will need to be much more to it in a final script, such as checking if the maximum has already been reached, and what to do from there, and also error handling for Input/Output errors, etc, but I think that is basically what you are trying to achieve, is it?. Not forgetting that I have omitted any reference to the file extension (*.zip, *.txt, etc). I guess you would want to pass the variables listed above (except for the loop counter) when you call the script, so that it can be used for a variety of purposes, rather than just for one specific project that you have in mind.
I'm not a real programmer, but I can understand logic reasonably well. I'm sure that others here can improve on the start that I have made, and maybe put it into a real programming language for you. Hope it helps somehow.
Edited by travstatesmen, 09 September 2008 - 08:34 AM.
#5
Posted 11 September 2008 - 11:44 AM
Thank you for the info you gave me, the language i wan't it to be written in is: VBscript.
I have some really basic knowlage about VBscript and I can simply copy files/folders to the place I want and rename it.
But that's where I got stuck.
So if someone could help me then I would be so happy.
When I'm home I will post the VBscript I have for copy and rename.
Thanks again.
#6
Posted 12 September 2008 - 07:41 AM
It makes a file with a temp name then it changes the .temp extension to .txt.
This will be repeated 100 times.
Set objFSO = CreateObject("Makefile.FileSystemObject")
For i = 1 to 100 ' For Next loop that runs from 1 to 100
strFileName = objFSO.GetTempName 'generates random files names
strFileName = Replace(strFileName, ".tmp", ".txt") 'changes .temp to .text
strPath = "c:\script\temp\" & strFileName 'path to the location where the files needed to be placed.
'if this script is placed in a folder like: c:\script
'and your strPath is c:\script\temp it
'wil not work it needs a "\" at the end.
objFSO.CreateTextFile(strPath) 'creates the file
Next
Edited by oxida, 12 September 2008 - 07:44 AM.
#7
Posted 24 October 2008 - 03:53 PM
How can I do it with VBS script?
Thanks.
Edited by sonice, 24 October 2008 - 03:55 PM.
#8
Posted 05 July 2009 - 11:28 PM
I have a similar, but simpler need, and please understand I am NOT a programmer :) ! All I need to be able to do is to RANDOMLY copy a file from a source directory to a destination directory. Trick is, it must be random! The command line would be:
RANDOM.EXE <SOURCE PATH> <DESTINATION PATH>
I had something someone had for the BBSs years ago, but I'll be damned if I can find it! Anyone able to help?? Many thanks!
-reply by Tom McElvy#9
Posted 21 July 2009 - 04:53 PM
Here is a script.
# Script randomcopy.txt
# Input argument source and dest paths.
var str source_path, dest_path
# Collect a list of files in source path.
var str list; lf -n "*" $source_path > $list
# Get a count of files in source path.
var int count; set $count = { len $list }
# Get number of seconds in current time.
var str seconds; chex "12[" gettime() > $seconds
# Generate a random number n between 1 and $count
var real n
set $n = ( makereal(str($seconds)) / 60 * $count ) + 1
# Get the $n'th file from our file list.
var str file; lex makestr(real($n)) $list > $file
# Copy $file to dest_path. Enclose both in double quotes as
# they may contain spaces, etc.
system copy ("\""+$file+"\"") ("\""+$dest_path+"\"")
The script is in biterscripting ( http://www.biterscripting.com ) . Save the script as C:\Scripts\randomcopy.txt. Start biterscripting. Enter the following command. (Enter the whole command on just one line. The source_path and dest_path are arguments passed to the randomcopy.txt script.)
script randomcopy.txt source_path("<SOURCE PATH>") dest_path("<DESTINATION_PATH>")
Change the <SOURCE PATH> and <DESTINATION PATH> to appropriate paths and make sure to enclose the paths in double quotes. The script can also be called directly from MS DOS, batch, perl, php, vbs or task scheduler. See the help page on batch.
Patrick
Edited by PatrickMc, 25 September 2009 - 02:06 PM.
#10
Posted 04 August 2009 - 12:30 PM
Hi All
I have a doubt, I want to check a file which is in Web. I want to check the file is exist or not. I have written a code which is giving me "False" . Where ifTyped the same URl in the browser I can see the File. I have given the sample code here please any body knows the solution please tell me.
Set fso = CreateObject("Scripting.FileSystemObject")
Msgbox fso.FileExists("http://Bangmsrira1 :8080/SampleProject/Book1.Xls")
It is showing false.
Thanks
-question by Jayarama
Reply to this topic

1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users














