Help with vbscript to create a file name from reading a text file

I am trying to have a vbscript file read a log file that has a file name in it.  Then I would like to change the name of the file in the directory to be the new name from the file.  Any suggestions would be greatfull .  I get an error each time saying bad file name or number on line 16

Const ForReading = 1


Set objFSO = CreateObject("Scripting.FileSystemObject")


Set objFile = objFSO.OpenTextFile("T:\365\rename\testrename\Log.txt", ForReading)

strCharacters = objFile.Read(70)
msgbox strcharacters
objFile.Close


strNewName = strCharacters
msgbox strnewname
objFSO.MoveFile "T:\365\rename\testrename\agood" , strNewName

Open in new window

LVL 1
ryan eIT ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewCommented:
"T:\365\rename\testrename\agood" is the name of an existing file?

What is the value of strNewName when line 16 executes?


»bp
0
ryan eIT ManagerAuthor Commented:
Thanks for the response bill

When I run the message box it shows that strnewName = the name Stream_Autocomplete_0_74D9645B844A494A8545116153EEEF34.dat
 in the log file

agood is the name of an existing file.  I have tried naming it agood or a.good and same result
0
Bill PrewCommented:
I think you may need the full path on the destination file, so it would need to be:

"T:\365\rename\testrename\Stream_Autocomplete_0_74D9645B844A494A8545116153EEEF34.dat"


»bp
0
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

ryan eIT ManagerAuthor Commented:
I will not know the exact name of the file so I can't do it that way. .  Each Machine I perform this on will have a different name.  Basically I have another script that gets the name of the dat file and then puts it into the log.  This script reads the log and then changes the name of the file to be what is in the log.
0
Bill PrewCommented:
Based on the code you posted, you already have the path to the file hard coded in the script as "T:\365\rename\testrename\agood", so I'm a little confused...


»bp
0
ryan eIT ManagerAuthor Commented:
Correct.  I have the path of where I will store the file.  The log file has the name Stream_Autocomplete_0_74D9645B844A494A8545116153EEEF34.dat in it (this will change)

I want to take what is in the log file (steam_autocomplete etc) and name the agood file to be Stream_Autocomplete_0_74D9645B844A494A8545116153EEEF34.dat
0
Bill PrewCommented:
Then just:

objFSO.MoveFile "T:\365\rename\testrename\agood" , "T:\365\rename\testrename\" & strNewName


»bp
0
ryan eIT ManagerAuthor Commented:
I've tried that also, but get the same result
path not found
0
Bill PrewCommented:
And drive T: is mapped when you run this, you aren't trying to run it from Task Scheduler or some other automated approach that runs in an environment where the user mappings are not defined?


»bp
0
ryan eIT ManagerAuthor Commented:
Drive T is mapped.

I even tried moving the entire 365 folder to my c: drive and running it that way and have had the same result    I am running from either double clicking the file or running from a command prompt
0
Bill PrewCommented:
I didn't notice this before, but you are doing a READ() agains the file, you want to do a READLINE().  Try this adjusted code.

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile("T:\365\rename\testrename\Log.txt", ForReading)

strNewName = objFile.ReadLine
MsgBox "[" & strcharacters & "]"
objFile.Close

objFSO.MoveFile "T:\365\rename\testrename\agood" , strNewName

Open in new window


»bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ryan eIT ManagerAuthor Commented:
DUDE......THAT WAS IT
0
Bill PrewCommented:
Yes, I should have seen that early, I just skipped right over the Read() assuming that part was working well, and focusing on the error line, with the rename...


»bp
0
ryan eIT ManagerAuthor Commented:
Thanks for th assistance
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.