[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Add a number after the foldername if typed foldername already exists

Posted on 1999-11-27
3
Medium Priority
?
321 Views
Last Modified: 2010-04-27
Hi!
I use the md command + inputbox function to create new folders. But when you create a folder with a name that already exists, there occurs an error. I want the an error handling that does like this:

When the folder name already exists I want the program to automatically add a number after the foldername. Like this:

New Folder
New Folder(2)
New Folder(3)
New Folder(4)
Etc.

(It is the same when you add new folder I in The Windows Explorer)

/Christian
0
Comment
Question by:ChristianJ
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
ggilman earned 800 total points
ID: 2237795
You didn't mention the language but since you mention "Input Box Function", I'm assuming Visual Basic. I have it working off a command button. If you want the path to be part of the input box, you can just get rid of it.

Private Sub Command1_Click()
Dim path As String
Dim fName As String
Dim curNum As Long

path = "c:\"
fName = InputBox("Enter Filename")
curNum = 1
While Dir(path & fName, vbDirectory) <> "" 'Check to see if it exists
  curNum = curNum + 1
  fName = "New Folder" & "(" & curNum & ")"
Wend
MkDir path & fName
End Sub
0
 
LVL 2

Expert Comment

by:ggilman
ID: 2237819
Oops...little problem with fName. Mine would always make the file be "New Folder" Here's the fix.

Private Sub Command1_Click()
Dim path As String
Dim fName As String
Dim inputName as String
Dim curNum As Long

path = "c:\"
inputName = InputBox("Enter Folder name")
fName = inputName
curNum = 1
While Dir(path & fName, vbDirectory) <> "" 'Check to see if it exists
  curNum = curNum + 1
  fName = inputName & "(" & curNum & ")"
Wend
MkDir path & fName
End Sub
0
 

Author Comment

by:ChristianJ
ID: 2246448
Sorry for not telling you I was using VB

Your code worked Excellent!!

THANKS!

/ChristianJ
0

Featured Post

Will You Be GDPR Compliant by 5/28/2018?

GDPR? That's a regulation for the European Union. But, if you collect data from customers or employees within the EU, then you need to know about GDPR and make sure your organization is compliant by May 2018. Check out our preparation checklist to make sure you're on track today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article outlines why you need to choose a backup solution that protects your entire environment – including your VMware ESXi and Microsoft Hyper-V virtualization hosts – not just your virtual machines.
Want to create a VM?  Here's how you do it.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…
Suggested Courses

611 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question