Re: Renaming a file..
- From: "Michel" <NoSp@xxxxx>
- Date: Fri, 9 Sep 2005 08:27:26 -0400
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
>
>
>
>
.
- References:
- Renaming a file..
- From: Michel
- Re: Renaming a file..
- From: Michael Harris \(MVP\)
- Re: Renaming a file..
- From: Michel
- Re: Renaming a file..
- From: Michel
- Re: Renaming a file..
- From: Michael Harris \(MVP\)
- Renaming a file..
- Prev by Date: Win32_NetworkAdapterConfiguration Loop through W2K machines
- Next by Date: Re: Appending lines to a txt file...
- Previous by thread: Re: Renaming a file..
- Next by thread: Internal pipes?
- Index(es):
Relevant Pages
|