Another batch file problem.

  Housten 14:40 14 Jul 2012

Good Afternoon [ !!! ],

I asked about what I thought was something easy, but after googling various things I am, now, more confused than ever! So I have revised what I want to do, and have realized – or think I have – that the simplest way would be to enter a number, right at the start of the file. And I must emphasize that – it will always be a number. This number will then be used to create a new sub-directory/sub-folder, which will then be written to. So what I want is something like:

Echo “What is number you wish to use”: Input %number% MD “G:\Mine\Backup\%number% [ or should this be %%number%%? ] ECHO OFF Xcopy “C:\bank data” “G:\Mine\Backup\%number%\bank data” and then I would use various parameters like ‘/s /e /c /h /y /v’ which I think will cover [ or more probably, more than cover ] all the options I will ever need, but I am going for the fullest amount so that once done, everything is covered and all bases are as well. As well as doing this folder and get it running properly, I will [ later ] be able to add other folders, and be able to save them where and when I want.

It is just getting the start correct that is proving really annoying, so if someone can tell me what to write I would be a very grateful pensioner.

Many thanks in anticipation.

  lotvic 19:33 14 Jul 2012

Is this the sort of script.vbs you want? Simple backup script download the .zip (you can look at and edit .vbs same way as .bat) also once you have unzipped the .vbs make a copy and save it as a .txt file so you can study it.

*Simple backup script One thing that keeps people from using backup scripts is complexity. I wrote this script to be as simple as possible. It copies new and updated files from a selected folder and its subfolders. Click on the folder to be updated, click on the backup folder, and copy. If you don't have a backup folder, the program can create one*, it asks you every step of the way. (if you want to keep the old backups as is, then create a new folder when you have to choose where to put the backup)

  Housten 12:35 15 Jul 2012


Good Afternoon,

Many thanks for your reply. But............NO!!

I saw your answer and decided to download and try it before, I replied to you. I downloaded it, then there was a problem copying it to the folder I wanted!! So I tried opening it, it asked for what I wanted and where, and that was all the input I was allowed!! I couldn't unzip I thought, but it must have somehow as it started running!! I then found out it was written in 2006, and that worried me. It then appeared to not show that it was working, but - completely accidentally - I found it was running in a DOS window, and looking at it there appeared to be a large number of folders it was denied access to and it could not create others!! Maybe I am being a bit paranoid but I want a programme - i.e. my own written one - whereby I knew, exactly, what was being done. I can not even see this programme or almost anything else to do with it, so I must say thank you very much for trying to help, but no thanks to the programme.

I will keep trying to find out how to ask for, and input, a number into a batch file and then to use that number to create new folder(s). What I want to have is the option to have several options so that, for instance, I can have one as a daily backup for one or two folders, another for a monthly backup with a weekly differential backup as well, another for copying files to and from a pendrive. These are quite simple to write, and with the 'goto' option quite easy to use, it is just this number input that is stifling me at the moment. Very frustrating!! But, Heigh Ho!!!!, in the fullness of time, at the the appropriate juncture I will work it out and then I will be a happy bunny old pensioner!!!

  lotvic 14:06 16 Jul 2012

To be able to use keyboard input in a batch you need the CHOICE command - and that is the limit of my knowledge so you could try a google :)

You say in other thread that you wanted to create Folders using Date as the Folder name. This intrigued me so have been 'looking and seeking' and I have found one way to do it (I'm using XP but you could try it in your W7). (There are shorter ways to put the commands but I have put them in full, separate, for ease of my understanding) For info on W7 available commands W7Commands and Batch File Commands

As pca site doesn't always display text in posts in the manner wanted I have done a screenshot pic of .bat and contents of Cmd window as it ran and put it on HERE

When composing batch file in Notepad I learnt do NOT have Wordwrap on.

The bat does this: Creates a folder using the current date and if such a folder already exists another folder is created with (2), (3) etc appended to make it unique. This .bat makes a folder in root C:\2010-07-16 if you run it again it makes another folder C:\2010-07-16 (2) and again C:\2010-07-16 (3) etc. up to C:\2010-07-16 (9) [if %inx% gtr 9 goto :END]

Also the delim / I checked in Control Panel > Regional&LanguageOptions, to make sure that my Windows date used the / separator, then I told .bat to use - when creating the new folder.

I haven't yet got into what to put to, set Path/make, or choose where the folder be created in another location so please tell me when/if you work it out :)

You will notice I have the ECHO ON and have put 'pause' in a couple of times so that I can see the command window as it does it. At the first pause if I didn't want to proceed to create the Folder (useful if output was not going to be what I wanted) I could end it there by closing Cmd window (I clicked on X top right). Also while it was paused I copied the contents of the cmd window to notepad (rightclick on bar at top of cmd window> edit > select all, then rightclick on bar at top of cmd window> edit > copy) and then paste into Notepad. This helped me see where I had gone wrong whilst sorting it out. I was having troubles with the Tokens, finally settled on 1-3 (ABC) - am learning as I go:)

To keep track of which bat gave me what, I copied and saved each .bat to a txt file (I renamed the copy from .bat to .txt) and then pasted in contents of cmd window underneath so that I could study them at my leisure.

I eventually found ClickHere that helped me understand Tokens, delims, variables etc.

Note: This line throughout "C:\Documents and Settings\lotvic\My Documents\Script kiddy" ONLY refers to where I have the .bat saved and where I go to click to run it.

Excuse the somewhat excessive details but anyone else reading/following may find them useful and I am a novice at this batch lark.

  Housten 12:50 17 Jul 2012


WOW!! This is going to take me an age tob get my head round this and then adapt it to my wishes. But this will not stop me tryimg!!!

Many thanks for your very kind help in this. I will let you know how it turns out - whatever mess I make of it!!

  Housten 16:39 17 Jul 2012


Good afternoon,

I hadn’t fully read and comprehended your last email when I wrote mine!! Brain dead pensioner again!!

So I have now gone through it – and the part batch file you included. I just wished I could have copied it, but couldn’t but copying DID improve my understanding of it! – and I will shortly start writing my batch file.

What I am trying to write is a backup file. One that will not give me the problems I have been having with some free commercial software. I have a 2 TB external USB HD and I have assigned the letter ‘W’ to it. So what I will do is to create a folder ‘W:\Ron’s\Year Month ( using your example ) for the first backup of the month, then when doing subsequent backups, the file will check if it exists and if so then will create a new folder of ‘W:\Ron’s\Year Month\Day’. The instructions will differ between the two sets only by the addition of ’d’ in the second set which will, effectively, become a differential backup. As one moves through the years and months then different backups will be automatically made and updated whenever I want to do so.

What I will also be doing in the file is checking if there is a backup that is 6 months old and deleting it. This is a little more complicated in that for the first 6 months of any year the backup file is for last year. However I have thought of a way round this and that is to give each backup a number and inserting it between ‘Ron’s’ and ‘Year’, and then when this reaches 7 – say – deleting 1, when this reaches 23 then delete 17. It maybe better to keep 12 months backups, so it will be just a case of edit the number that has to be deducted from current number. One way I have thought that this could be done – but I have not quite how to work it out – is to save the ‘Month Year’ to a file with an associated number, this is then called when the file starts and if the current ‘Month Year’ is the same then number stays same, but if current ‘Year Month’ are different then 1 is added and everything proceeds as before, with new folders being created. I did think of using ‘A’, ‘B’, ‘C’ etc but it gets complicated when you go beyond ‘Z’, whereas numbers just keep going. Perhaps I am being cheeky here but if anyone has an idea how to do this – i.e. save me having to workout and write code for this – I would be very grateful!!

I know some might think that I am deliberately making work for myself by having to have more than one set of instructions, but to be honest most of the second set(s) will be a duplicate of the first so I will be able to ‘copy and paste’ and do a small amount of editing to get everything done. So what if the batch file grows to be 10, 20, 30 or even 40 K, this is a lot less than free commercial software most of which run to over 100 MB and this will do the exact backups that I require NOT ones which somebody else thinks I should have!!!

Of course, the only thing left for me to do now is the worst part, actually write and test it!!!! But it is really only a case of making certain that it works correctly for one instance, and then the rest can be copied, much the same as I used to write my BASIC programmes – well known hope or phrase!!!

I will let you know how it all goes – or not!!

  lotvic 16:39 17 Jul 2012

I should also have said: if you want to read a .vbs file to look at the coding then make a copy of it and change the ext .vbs to .txt and save it, it will then open in notepad. (yes I know you can rightclick > edit and also rightclick and choose notepad to open the original, but I prefer to work with copies)

Intriguing stuff this, when you are new to it like me :)

  robin_x 17:16 17 Jul 2012

I am following with occasional interest too. I haven't the time to mess around and refresh my very limited skills though.

One comment.

I am always wary of special characters in file and folder names. Even if allowed.

So I would call my folder Rons or just Ron. Just in case of confusion, typos or problems.

Have fun.

  lotvic 17:35 17 Jul 2012

robinofloxley, do you mean add another Token 1-4? (token 4 being D that would insert Ron after the date). It might be next week before I have time to play again with it :)

  robin_x 17:57 17 Jul 2012

No I just meant using apostrophes in general.

I may be overly cautious.

  lotvic 18:28 17 Jul 2012

I misunderstood, I see now you meant the actual word Ron's to not have an apostrophe.

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

Best Black Friday Deals 2017

How modern book design was influenced by illustrated manuscripts

Best Black Friday Apple Deals 2017

Les meilleurs logiciels de montage vidéo gratuits (en 2017)