S
S
ssssergey2015-04-05 08:51:28
cmd/bat
ssssergey, 2015-04-05 08:51:28

How to create a folder with the name: word + increasing index using a bat file?

It is necessary that each time the bat file is called, a folder is created with the same dictionary base, but with an increased index.
For example, we check the existence of a folder called "Word 1". If it exists, then copy it there. If not, we check for the presence of a folder called "Word 2", and so on.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
B
bobrovskyserg, 2015-04-05
@bobrovskyserg

You seem to know Python - write a script on it.

J
John Smith, 2015-04-06
@ClearAirTurbulence

It's easier to do this in VBSCRIPT than in bat. Well, or in python, as advised above.
If on vbscript, then, being a non-specialist, I would recommend the following approach.
The basic code for creating a folder is shown below.
It will be necessary to modify it slightly with a file:
- set it at the beginning through a constant, so that later, if the word has changed, the folder name is not changed everywhere (the text part, for example, "foldername="Word""
- measure its length using len(foldername)
- knowing foldername and its length, modify the code below (the part marked with asterisks) to check for folders containing foldername + "something"
- if there are any, for each found instance, cut off from the name "something", check if it is a number "something", if it is a number - find the maximum of these numbers
- increment the maximum number, create the folder "% foldername% % incremented_max_number %"
- if folders are not found by checking, create "%foldername% 1".

' NewFolderEC.vbs
' Free example VBScript to create a folder with error-correcting Code.
' Author Guy Thomas http://computerperformance.co.uk/
' Version 2.6 - May 2010
' ------------------------------------------------' 

Option Explicit
Dim objFSO, objFolder, objShell, strDirectory
strDirectory = "c:\logs"

' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Note If..Exists. Then, Else ... End If construction *********
If objFSO.FolderExists(strDirectory) Then
   Set objFolder = objFSO.GetFolder(strDirectory)
   WScript.Echo strDirectory & " already created "
Else
   Set objFolder = objFSO.CreateFolder(strDirectory)
WScript.Echo "Just created " & strDirectory
End If
' Note If..Exists. Then, Else ... End If construction *********

If err.number = vbEmpty then
   Set objShell = CreateObject("WScript.Shell")
   objShell.run ("Explorer" &" " & strDirectory & "\" )
Else WScript.echo "VBScript Error: " & err.number
End If

WScript.Quit

' End of Sample VBScript to create a folder with error-correcting Code

M
Max, 2015-06-09
@MaxDukov

SET DIR = c:\test
SET WORD = XYZ
FOR /L %i IN (1,1,99999999) DO (
IF EXIST %DIR%%WORD%%i COPY -- what did you want to copy there
)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question