Computing.Net > Forums > Disk Operating System > batch file

batch file

Reply to Message Icon

Original Message
Name: Peter
Date: December 12, 2000 at 02:50:13 Pacific
Subject: batch file
Comment:

I am trying to create a batch file that will copy a text file from one folder to another
then if the file in that folder has the same name as the one i am copying(which it will) to either rename the one i am copying or the one that resides there the hard part is i need these files to continuley increment ie: file1.txt file2.txt file3.txt
Any help would be greatly appreciated


Report Offensive Message For Removal


Response Number 1
Name: pat
Date: December 12, 2000 at 05:53:38 Pacific
Subject: batch file
Reply: (edit)

use the if exist command
eg if exist xxx.xxx rename xxx.xxx yyy.yyy
Dont forget to put this before you copy the new file to the directory or it will rename the one you want to keep.
Im not so sure on how to sequentially number the files though You may have to use the date of creation to keep them straight else you will have to rename all of the older files each time you add a new one since you probably would want 1 to become 2 and so on. then if 2 needed to be 3 the next time you ran the bat it would error due to 3 already being there. The only other way I can think of would be to reverse the order of the saved files eg xxx.xxx would become xxx1.xxx and the next copy would be xxx2.xxx. This way you wouldnt need to rename anythng except the file you are copying but if you need to call that file you will need to know the last number you used. It obviously wouldnt be xxx1.xxx all of the time. HTH


Report Offensive Follow Up For Removal

Response Number 2
Name: Peter
Date: December 12, 2000 at 15:43:22 Pacific
Subject: batch file
Reply: (edit)

Thank you pat i will try what you suggested and see if i can get this to work
i Will let you know how it turns out

Thanks again


Report Offensive Follow Up For Removal

Response Number 3
Name: Peter
Date: December 12, 2000 at 18:56:47 Pacific
Subject: batch file
Reply: (edit)

Well i tried what you suggested Pat
worked fine
but i still cant get the sequential part to happen
I Keep getting told it cant be done
Thx for your effort


Report Offensive Follow Up For Removal

Response Number 4
Name: Laurence
Date: December 13, 2000 at 10:39:15 Pacific
Subject: batch file
Reply: (edit)

I don't have time for that one right now,
but ask this question in
news:alt.msdos.batch

Lots of people there know how to do it.




Batfiles: The DOS batch file programming handbook




Report Offensive Follow Up For Removal

Response Number 5
Name: troehl
Date: January 1, 2001 at 20:11:34 Pacific
Subject: batch file
Reply: (edit)

ou want to sequentialy name the new files being copied from one folder to another.

IE : \folder1\newfile.txt --> copy --> \folder2\filename.txt (1) ,(2), etc

The following will work, and you will need to extend it to as many numbers of files you expect to have. Be sure that the numbers run from larger to smaller.


IF EXIST \FOLDER2\FILENAME9.TXT COPY \FOLDER1\NEWFILE.TXT \FOLDER2\FILENAME10.TXT
IF EXIST \FOLDER2\FILENAME8.TXT COPY \FOLDER1\NEWFILE.TXT \FOLDER2\FILENAME9.TXT
.. ( etc)

the logic is if # 9 exist then name it # 10 --- if # 8 exist name it # 9 )

I hope you don't have 100 or more files, it could make for a long list, but it will work.


Report Offensive Follow Up For Removal


Response Number 6
Name: troehl
Date: January 2, 2001 at 05:59:26 Pacific
Subject: batch file
Reply: (edit)

Sorry about the example in the previous post... I blew it !! I'll try and follow up with an example that works.


Report Offensive Follow Up For Removal

Response Number 7
Name: troehl
Date: January 2, 2001 at 06:13:02 Pacific
Subject: batch file
Reply: (edit)

Sorry about the example in the previous post... I blew it !! I'll try and follow up with an example that works.

++++++++++++++++++++
OK, here are the command lines you need--


IE: \folder1\newfile.txt you want to copy this sequentially to \folder2

if exist \folder2\filename1.txt set name=filename2
if exist \folder2\filename2.txt set name=filename3
if exist \folder2\filename3.txt set name=filename4
.... etc....

( Dos will drop through these lines, until the last valid ' if exist ' is true.)

Then you use the following ..

copy \folder1\newfile.txt \folder2\%name%.txt



Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: batch file

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 2 Days.
Discuss in The Lounge