linuxrox
asked on
How do I create a function that loops through folders to see if a folder exists and create a new folder?
Hello. So here is what I need. I need a function that accepts a folder path like, "C:\users\myuser" and checks to see if that folder exists and if it does exist it needs to append a "1" to the end of 'myuser' and continue to check if the appended folder name exists until it finds a folder that does NOT exist and return that folder path. I may have "myuser1" and "myuser2" existing but "myuser3" is available. so i would need my function to return that path to my main function so it could create the folder and move on with it's other operations.
basically i have a main function that does a lot of operations and one part of the operation is to call a function that checks if a folder name is available for creation.
anyone help with that?
thanks
basically i have a main function that does a lot of operations and one part of the operation is to call a function that checks if a folder name is available for creation.
anyone help with that?
thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Baleboos: There are no files in the root folder where the folders are being created so there is no need to check for existing files with the same name. these are basically home folders for users in active directory and they are all created on a main root drive for which no files exist.
ASKER
This was exactly what I was trying to achieve.
1) You don't check if file exists. You can't name a directory the same as a file. And because you need to check files as well, you need to get rid of the trailing slash.
2) Author wants the directory path string, not the directory.
Linuxrox: your solution also has the first problem.