I have having a very strange occurrence when looping through a text
file.

objective:

Loop through text file list of username and then rename their
corresponding folder to username.old.

sounds simple.....

Code:

Dim objFSO
Dim ulist

On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ulist = objFSO.OpenTextFile("ren2.txt",1,False)

Do Until ulist.AtEndOfStream
WScript.Echo ulist.ReadLine

objFSO.MoveFolder "z:\profilerename\folders\"&uname, "z:\profilerename
\folders\"&uname&".old"

Loop





If I run the code with the action commented out I am able to enumerate
all the names.

But, when I am performing the action it is actually skipping lines for
the text file.

Ex. It would show it was working on line1 but actually do line2.

Very bizarre

Has anyone seen anything like this before?

Paul

Re: Scripting oddity by Richard

Richard
Thu May 17 13:05:41 CDT 2007

Paul wrote:

>I have having a very strange occurrence when looping through a text
> file.
>
> objective:
>
> Loop through text file list of username and then rename their
> corresponding folder to username.old.
>
> sounds simple.....
>
> Code:
>
> Dim objFSO
> Dim ulist
>
> On Error Resume Next
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set ulist = objFSO.OpenTextFile("ren2.txt",1,False)
>
> Do Until ulist.AtEndOfStream
> WScript.Echo ulist.ReadLine
>
> objFSO.MoveFolder "z:\profilerename\folders\"&uname, "z:\profilerename
> \folders\"&uname&".old"
>
> Loop
>
>
> If I run the code with the action commented out I am able to enumerate
> all the names.
>
> But, when I am performing the action it is actually skipping lines for
> the text file.
>
> Ex. It would show it was working on line1 but actually do line2.
>
> Very bizarre

My guess is that you left out a statement where a value is assigned to the
variable uname. The Wscript.Echo statement reads one name, then the
statement that assigns a value to uname reads the next name in the file. I
would suggest:

Do Until ulist.AtEndOfStream
uname = ulist.ReadLine
WScript.Echo uname

objFSO.MoveFolder "z:\profilerename\folders\" & uname, _
"z:\profilerename\folders\" & uname & ".old"
Loop

You need to make sure you only invoke the ReadLine method once per loop.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--



Re: Scripting oddity by Tom

Tom
Thu May 17 13:30:13 CDT 2007

On May 17, 1:08 pm, pjglick <pglickenh...@njm.com> wrote:
> I have having a very strange occurrence when looping through a text
> file.
>
> objective:
>
> Loop through text file list of username and then rename their
> corresponding folder to username.old.
>
> sounds simple.....
>
> Code:
>
> Dim objFSO
> Dim ulist
>
> On Error Resume Next
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set ulist = objFSO.OpenTextFile("ren2.txt",1,False)
>
> Do Until ulist.AtEndOfStream
> WScript.Echo ulist.ReadLine
>
> objFSO.MoveFolder "z:\profilerename\folders\"&uname, "z:\profilerename
> \folders\"&uname&".old"
>
> Loop
>
> If I run the code with the action commented out I am able to enumerate
> all the names.
>
> But, when I am performing the action it is actually skipping lines for
> the text file.
>
> Ex. It would show it was working on line1 but actually do line2.
>
> Very bizarre
>
> Has anyone seen anything like this before?
>
> Paul

Where exactly do you set uname equal to the name of the file from the
list? Is there a line missing from the posted code? Maybe one that
performs another Readline?

My personal choice would be to read the entire file into an array and
then process the array, something like this ...

Dim ulist

' Kill this line until it all works - On Error Resume Next
with CreateObject("Scripting.FileSystemObject")
Set ulist = .OpenTextFile("ren2.txt",1,False)

For each uname in Split(ulist.ReadAll, vbNewline)
wsh.echo "Processing: ", uname
sFolderSpec = "z:\profilerename\folders\" & uname
if .FolderExists(sFolderSpec) then
.MoveFolder sFolderSpec, sFolderSpec & ".old"
else
wsh.echo sFolderSpec, "not found"
end if
Next ' uname
end with ' FSO

Tom Lavedas
==========
http://members.cox.net/tglbatch/wsh/


Re: Scripting oddity by D

D
Thu May 17 17:32:46 CDT 2007

Hi PG,

Sounds to me like the On Error Resume Next is stopping you from seeing a
failed move.

Try using Option Explicit, and not using a global On Error Resume Next,
e.g.:


Option Explicit
Dim objFSO
Dim ulist, urec

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ulist = objFSO.OpenTextFile("ren2.txt",1,False)

Do Until ulist.AtEndOfStream
urec = ulist.ReadLine
WScript.Echo urec

On Error Resume Next
objFSO.MoveFolder "z:\profilerename\folders\"&urec,
"z:\profilerename\folders\"&urec&".old"
If Err.Number <> 0 Then WScript.Echo "Move/rename failed..."
On Error Goto 0
Loop

WScript.Quit(0)



HTH,
Regards,
Dave.






"pjglick" <pglickenhaus@njm.com> wrote in message
news:1179421723.124203.43840@l77g2000hsb.googlegroups.com...
>I have having a very strange occurrence when looping through a text
> file.
>
> objective:
>
> Loop through text file list of username and then rename their
> corresponding folder to username.old.
>
> sounds simple.....
>
> Code:
>
> Dim objFSO
> Dim ulist
>
> On Error Resume Next
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set ulist = objFSO.OpenTextFile("ren2.txt",1,False)
>
> Do Until ulist.AtEndOfStream
> WScript.Echo ulist.ReadLine
>
> objFSO.MoveFolder "z:\profilerename\folders\"&uname, "z:\profilerename
> \folders\"&uname&".old"
>
> Loop
>
>
>
>
>
> If I run the code with the action commented out I am able to enumerate
> all the names.
>
> But, when I am performing the action it is actually skipping lines for
> the text file.
>
> Ex. It would show it was working on line1 but actually do line2.
>
> Very bizarre
>
> Has anyone seen anything like this before?
>
> Paul
>



Re: Scripting oddity by ekkehard

ekkehard
Wed May 23 16:18:51 CDT 2007

Tom Lavedas schrieb:
> On May 17, 1:08 pm, pjglick <pglickenh...@njm.com> wrote:
>> I have having a very strange occurrence when looping through a text
>> file.
>>
[...]
>> Paul
>
[...]
> My personal choice would be to read the entire file into an array and
> then process the array, something like this ...
>
[...]
> Tom Lavedas
> ==========
> http://members.cox.net/tglbatch/wsh/

My personal choice would be just the opposite. If you don't need
random access to the file's data, there is nothing to gain from
building an additional data structure in memory. Furthermore there
is always the risk of getting an empty last array element for the
last (delimiting) vbCrLf that Split sees as a separator.

But that is just my opinion - and I'm here to learn. Therefore I
would be interested in your reasons for your choice.

Thanks.