zachvaldez
asked on
Renaming a file
I have text files in C:\folder\ListofSchools. These textfiles uses their IDs as file names.
Ex.
39991.txt
29221.txt
.... etc
However, in the database, their codeDesc are..
id codeDEsc
39991 Prarie
29211 Westwind.
Id like to rename the ids or replace it with their codeDesc ..
I was thinking of creating a stored procedure that will extract the name from Id such as
Select codeDesc from tblSchool where id = the file name that is listed in the folder..
question..
What will be the code to loop to the folder?
What code to rename the id with the code desc?
Has anyone done this directory or file processing?
I appreciate if you can send me code examples how it is done?
Ex.
39991.txt
29221.txt
.... etc
However, in the database, their codeDesc are..
id codeDEsc
39991 Prarie
29211 Westwind.
Id like to rename the ids or replace it with their codeDesc ..
I was thinking of creating a stored procedure that will extract the name from Id such as
Select codeDesc from tblSchool where id = the file name that is listed in the folder..
question..
What will be the code to loop to the folder?
What code to rename the id with the code desc?
Has anyone done this directory or file processing?
I appreciate if you can send me code examples how it is done?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Well, I did it that way because I think that it's better and much optimized to access the database only one time.
@RolandDeschain, didn't mean to knock on your solution. It is much better optimized to access the database one time. I had already taken the time to write up my solution before seeing that you posted. My solution, while less efficient, seemed possibly easier to read or understand if the poster was looking at the problem from the file system instead of what was the most efficient.
You solution is the more efficient solution, but I thought mine might have some merit in looking at the solution from the other side.
@zachvaldez, you should use RolandDeschain's solution if it makes sense and works for you.
You solution is the more efficient solution, but I thought mine might have some merit in looking at the solution from the other side.
@zachvaldez, you should use RolandDeschain's solution if it makes sense and works for you.
ASKER
Just a question. Why isn't any parameter pass like
"where id = @param
@param being the currentfile name which is the id?
and as it loops th @param changes... and renames it with the description...
"where id = @param
@param being the currentfile name which is the id?
and as it loops th @param changes... and renames it with the description...
ASKER
@RolandDeschain code is doing what it supposed to .
However if the name has "/" as "Dogwood/Subway" on that Id, it errors out and stops the loop.
What the best way to handle this?
However if the name has "/" as "Dogwood/Subway" on that Id, it errors out and stops the loop.
What the best way to handle this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Both approaches worked!
Open in new window
The function getCodeDescFromDatabase is where you would call your stored procedure to lookup the value in the database.