Re: Renaming a file..

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Tahnks a lot, it works perfectly.

"Michael Harris (MVP)" <mikhar at mvps dot org> wrote in message
news:ejMHDeNtFHA.596@xxxxxxxxxxxxxxxxxxxxxxx
> Michel wrote:
>> Hi Harris, Finally I followed you suggestion and made my script for
>> renaming a file, but I want to keep track, you know like a Log, but I
>> can't add a line to the text file, at least the correct one(It adds
>> a very weird characters instead of right ones).. Any Idea???
>
>
> The arguments of OpenTextFile and CreateTextFile are not the same, in
> particular the 3rd argument.
>
> A local copy of the documentation is a *must* ;-)...
>
> Download details: Windows Script Documentation
> http://www.microsoft.com/downloads/details.aspx?FamilyID=01592c48-207d-4be1-8a76-1c4099d7bbb9&DisplayLang=en
>
>
> For OpenTextFile, using True as the 3rd argument means create the file if
> it doesn't exist.
>
> For CreateTextFile, using True as the 3rd argument means create the file
> as Unicode format rather than the default of ASCII.
>
> So when the file is created/written to the 1st time, it is in Unicode
> format. When you later open it for appending, it is opened/written to by
> default as an ASCII file. For OpenTextFile, it's the 4th argument that
> controls Unicode/ASCII format.
>
> The fix (assuming you want a simple ASCII file), is to drop the 3rd
> argument in the CreateTextFile call. Or more simply, drop the If test for
> existence (and the else block) completely and just use your existing
> OpenTextFile call. As written, the OpenTextFile will create the file (in
> ASCII format) as needed before appending to it the first time and just
> open it (again as ASCII) for appending every time after that.
>
>
>> This is the script:
>> *******************************************************
>> Const ForAppending = 8
>> const ForReading = 1
>> const ForWriting = 2
>> const TristateFalse = 0
>>
>> Set fso = CreateObject("Scripting.FileSystemObject")
>> if fso.FileExists("C:\backup.bkf") then
>> Set file = fso.GetFile("C:\backup.bkf")
>> logline = file.Name & " " & file.path & " " & file.DateCreated & " " &
>> file.DateLastModified & " "
>> logline = logline & file.Size
>> dim s
>> s = file.DateLastModified
>> s = replace(s, "/", "-")
>> s= replace (s, ":", "-")
>> s= replace (s, " ", "_")
>> file.name = "backup_" & s & ".bkf"
>> if fso.FileExists("C:\RenameBackupLog.txt") then
>> Set logfile =
>> fso.OpenTextFile("c:\RenameBackupLog.txt",ForAppending,true)
>> logfile.WriteLine(logline)
>> wScript.Echo logline
>> logfile.Close
>> else
>> Set logfile = fso.CreateTextFile("c:\RenameBackupLog.txt",
>> ForAppending,true)
>> logfile.WriteLine("File renamed: ")
>> logfile.Close
>> end if
>>
>> Else
>> wScript.Echo "File not found"
>> end if
>> *******************************************************
>>
>> "Michel" <NoSp@xxxxx> wrote in message
>> news:Oz8rTfvsFHA.2212@xxxxxxxxxxxxxxxxxxxxxxx
>>> Thank U.
>>>
>>> "Michael Harris (MVP)" <mikhar at mvps dot org> wrote in message
>>> news:uz6BDLBsFHA.2064@xxxxxxxxxxxxxxxxxxxxxxx
>>>> Michel wrote:
>>>>> Hello, can somebody help to make a script for renaming a file...
>>>>> Thanks in advanced.
>>>>> Michel
>>>>
>>>> Use the FSO method GetFile to get a File object reference which has
>>>> a read/write Name property.
>>>>
>>>> --
>>>> Michael Harris
>>>> Microsoft MVP Scripting
>
> --
> Michael Harris
> Microsoft MVP Scripting
>
>
>
>


.



Relevant Pages

  • Re: Renaming a file..
    ... Download details: Windows Script Documentation ... For OpenTextFile, using True as the 3rd argument means create the file if it ... Unicode format rather than the default of ASCII. ... >>> Michael Harris ...
    (microsoft.public.scripting.vbscript)
  • Re: Setting environment variables in IIS 6.0 [PERL @INC MANIPULATION]
    ... included the sample drsaticly reduced VBS script below - the script will add ... > Only option I can think of is to write to the IIS Admin APIs using script. ... Const L_ChkCmdLibReg_ErrorMessage = "Please register the ...
    (microsoft.public.inetserver.iis)
  • Script not Functioning Properly
    ... the script is supposed to automatically reply to any new ... Const CdoPR_ACTION_FLAG = &H10810003 ... Public Sub Folder_OnMessageCreated ...
    (microsoft.public.outlook.program_vba)
  • Re: From Workgroup to Domain
    ... Ok thank you for the help - nice to see the script run:) ... it should help the win2k clients. ... Gibraltar skrev: ... Const JOIN_DOMAIN = 1 ...
    (microsoft.public.windows.server.active_directory)
  • [code] getting your script to talk to you
    ... SAPI comes as an actX object, and so is programmable using vbs. ... There was only one small script for sapi that I could find here, ... Dim oSpVoice, sText ... Const SVSF_Default = 0 ...
    (microsoft.public.scripting.vbscript)