| | Hi all. I want to make a VBScript wich does the following: Copy a file like test.txt if test.txt already exists then name it test1.txt and so on until i have xxx number of files. If someone could help me or post a script I would be happy xD Thanks, |
| Nov 21, 2009 |
If you mind some software that would do the work for you, then I would recommend Renamer. I have used this utility in many similar situtations as yours. And this software is very useful to rename files in large quantities. Also it offers a variety of features like regular expressions and so on. Just check it to be sure if it works for you. Believe me, I myself didn't get the time to completely explore its features.
If you mind some software that would do the work for you, then I would recommend Renamer. I have used this utility in many similar situtations as yours. And this software is very useful to rename files in large quantities. Also it offers a variety of features like regular expressions and so on. Just check it to be sure if it works for you. Believe me, I myself didn't get the time to completely explore its features. 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. 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.trap17.com/backups/latestbackup.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.... CODE '**** 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.
Travstatesmen, that's exactly what I want to do.
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.
Well I found something simmiliar.
It makes a file with a temp name then it changes the .temp extension to .txt. This will be repeated 100 times. CODE 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
Hi in my situation I have for example 32132131346879.zip the file generated in C:/temp by my PC and I need to find the way for this file to be renamed to text.zip and this 32132131346879 randomly changed each time...
How can I do it with VBS script? Thanks.
Similar need
Copy A File And Rename It With Increment If Exist 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
You want to randomly copy a file from <SOURCE PATH> to <DESTINATION PATH>.
Here is a script. CODE # 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.) CODE 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
how to check a file is exist or not
Copy A File And Rename It With Increment If Exist 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
Similar Topics
Keywords : copy, file, rename, increment, exist, vbscript
batch file help (6) I wish to execute a command at regular intervals .....precisely every half an hour....Is there any Make Notepad as default file opener (7) Open Any Unknown File with Notepad can you check my code and information? (2) Okay, so here's the situation. For one of my school projects I have decided to do a simple Looking for copy, file, rename, increment, exist, vbscript
|
![]() Copy A File And Rename It With Increment If Exist - in VBScript |
Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com