Re: Debugging Help Please! :) File renaming...

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



The array consists of instances of any file with extension PST on a
given computer. So if it finds more than one file with the same name -
for example, outlook.pst - then it is supposed to rename them
including the file creation date as part of the filename.

On Sep 13, 11:59 am, knothead <knoth...@xxxxxxxxxxxxxxxxxxxxxxxxx>
wrote:
When you say files with the same please explain more. Are you meaning
users1000 and users1001? Are you counting the first eight characters?

Me me you need more logic in last Else clause.  

Else

"onebucktraf...@xxxxxxxxx" wrote:
Thanks for reading this.

This code segment is part of a larger script that moves PST files so
that they are accessible to users anywhere in the network. The rest of
the script works but this is making me nuts. This is supposed to
determine if two or more files have the same name, and if so, rename
them to include the file dat or timestamp as well. It doesn't work.
Can some offer some guidance?

DI

'[Rename Code] - Renames PST files with timestamp
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
\cimv2")

Set FileList = objWMIService.ExecQuery _
    ("ASSOCIATORS OF {Win32_Directory.Name='y:\mailbox'} Where " _
        & "ResultClass = CIM_DataFile")

For Each objFile In FileList
    strDate = Left(objFile.FileName & "_" & objFile.CreationDate, 30)
    strNewName = objFile.Drive & objFile.Path & _
       strDate & "." & "pst"
    strNameCheck = Replace(strNewName, "\", "\\")

    i = 1
    Do While True
        Set colFiles = objWMIService.ExecQuery _
            ("Select * from Cim_Datafile Where Name = '" &
strNameCheck & "'")
        If colFiles.Count = 0 Then
            errResult = objFile.Rename(strNewName)
            Exit Do
        Else
            i = i + 1
            strNewName = objFile.Drive & objFile.Path & _
               strDate & "_" & i & "." & "pst"
            strNameCheck = Replace(strNewName, "\", "\\")
        End If
    Loop
Next
'[End Rename Code]

.



Relevant Pages

  • Re: Ask for help about the structure
    ... since `monstr' is never used.) ... or you could wipe out the old data ... ... why not just use the rename() function to change ...
    (comp.lang.c)
  • Re: renameTo method suddenly stopped working...
    ... rename failed, but is secretive about the reasonfor failure. ... it, but as soon as I change the source file, not only does the source ... "You fucking son of a bitch. ...     to writer and editor Al Hunt, ...
    (comp.lang.java.programmer)
  • Re: subprocess.popen function with quotes
    ... command will probably work better if you avoid using shell=True. ...     command, ... waitfunction - but when there is an error with the call to rename ... just terminates and displays the error). ...
    (comp.lang.python)
  • Re: Renaming and Moving Files:
    ... filler, right? ... I'd like to rename one file and move another. ... When I tried (res is the existing file), ...
    (comp.lang.java.programmer)