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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

batch file

Reply to Message Icon

Name: Peter
Date: December 12, 2000 at 02:50:13 Pacific
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



Sponsored Link
Ads by Google

Response Number 1
Name: pat
Date: December 12, 2000 at 05:53:38 Pacific
Reply:

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


0

Response Number 2
Name: Peter
Date: December 12, 2000 at 15:43:22 Pacific
Reply:

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


0

Response Number 3
Name: Peter
Date: December 12, 2000 at 18:56:47 Pacific
Reply:

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


0

Response Number 4
Name: Laurence
Date: December 13, 2000 at 10:39:15 Pacific
Reply:

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




0

Response Number 5
Name: troehl
Date: January 1, 2001 at 20:11:34 Pacific
Reply:

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.


0

Related Posts

See More



Response Number 6
Name: troehl
Date: January 2, 2001 at 05:59:26 Pacific
Reply:

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


0

Response Number 7
Name: troehl
Date: January 2, 2001 at 06:13:02 Pacific
Reply:

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



0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: batch file

Help!! Batch File www.computing.net/answers/dos/help-batch-file/13525.html

Batch files - - Mapping network drive www.computing.net/answers/dos/batch-files-mapping-network-drive/3809.html

Pause batch file www.computing.net/answers/dos/pause-batch-file/2810.html