Link to home
Start Free TrialLog in
Avatar of texaspete
texaspete

asked on

VBscript FSO.MoveFolder failing when not hard coded

Hi There,

I'm trying to tidy up some folder names with a vbscript.

e.g. rename folder 'msgid_123456_Filename_date_version' to 'Filename date version'

I've done all the tidying and have two variables with the before and after folder names in.

If I run the code:

objFSO.MoveFolder "c:\msgid_123456_Filename_date_version" , "C:\Filename date version"

It works fine and renames the folder no problem.

If I try to use variables it seems to fail: I've tried several ways

==========================
strBefore = "'" & strBefore & "'"
strAfter = "'" & strAfter & "'"

objFSO.MoveFolder strBefore,strAfter
==========================

==========================
strBefore = chr(34) & strBefore & chr(34)
strAfter = chr(34) & strAfter & chr(34)

objFSO.MoveFolder strBefore,strAfter
==========================

As soon as I try to use variables with the movefolder command I get "Bad filename or number" error message on the movefolder line

Also if echo strBefore and strAfter on the screen they are exactly as I want them and definately point the correct folders with no spelling mistakes.

Does anyone have any ideas??



Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

you don't need the quotes in the filename variables.

strBefore = "c:\msgid_123456_Filename_date_version"
strAfter = "C:\Filename date version"

objFSO.MoveFolder strBefore,strAfter
Avatar of texaspete
texaspete

ASKER

I'm not sure what you mean. in your reply you have quotes in

Besides, I'm not hard coding strBefore and strAfter. They are variables and are part of a loop so they will both be different each loop. If I leave the quotes out and one of the folder names has a space in it I get a "path not found" error on the MoveFolder line.
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
fixed it!

sorry for the delay i've been on leave. It was erroring at a different line. When the script loops and checks the subfolder the rename had already happened and the folder loop variable hadn't been updated with the new name of the renamed folder.

saying that I probably would have still been messing around with quotes by now so have the points

TP