Computing.Net > Forums > Programming > Batch file: rename file based on fs

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file: rename file based on fs

Reply to Message Icon

Name: brownbear (by BrownBear)
Date: August 5, 2008 at 12:49:32 Pacific
OS: Win Server 2003
CPU/Ram: Xeon-4GB
Product: IBM 3550
Comment:

I need to create a "simple" batch file that will not only rename a specified file to the date it was renamed (example: batch.log to batch-080508.log) but also based on the file size limit (example: if file size is less than 50MB, please rename batch.log to batch-080508.log)

Thanks,
BB



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: August 5, 2008 at 18:25:59 Pacific
Reply:

vbscript


strYr=Year(Now)
strMth=Month(Now)
strDay = Day(Now)
If Len(strMth) < 2 Then
strMth="0"&strMth
End If
If Len(strDay) < 2 Then
strDay="0"&strDay
End If
strDate=strDay&strMth&strYr
On Error Goto 0
Set objArgs = WScript.Arguments
strFileName=objArgs(0)

Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFile=objFS.GetFile(strFileName)
If objFile.Size < 5000000 Then 'i leave it to you to change it to bytes
strNewName = Split(strFileName,".")
objFS.MoveFile objFile.Path , objFile.ParentFolder & "\" & strNewName(0)&"-"&strDate&"."&strNewName(1)
End If

on the command line


c:\test> cscript /nologo script.vbs myfiletorename


0

Response Number 2
Name: Razor2.3
Date: August 5, 2008 at 19:17:03 Pacific
Reply:

Hey ghostdog, I've got somethin' to say! (Don't I always?)

<nitpick>'i leave it to you to change it to bytes
Was 50 * 2 ^ 20 too much? Really? </nitpick>

objFS.MoveFile
objFile.Name might be a better choice.


0

Response Number 3
Name: ghostdog
Date: August 5, 2008 at 19:45:06 Pacific
Reply:

@razor, you are right, i forgot about those. Guess i am rusty with vbscript. :)
btw, i noticed about the forum's new look, but it lacks features. i wonder if the forum allows [url][/url]


0

Response Number 4
Name: Razor2.3
Date: August 5, 2008 at 19:58:23 Pacific
Reply:

[url][/url], no.
< a href></a >, yes. (See the .Name part in my last post)

Excluding the skin, everything is identical to before, bugs and all.


0

Response Number 5
Name: ghostdog
Date: August 5, 2008 at 20:50:57 Pacific
Reply:

thanks.


0

Related Posts

See More



Response Number 6
Name: brownbear (by BrownBear)
Date: August 6, 2008 at 09:11:10 Pacific
Reply:

ghostdog, thanks a lot! When I try to run it, I get "Microsoft VBScript Compilation Error: Expected Statement." I did change part of it using Razor's correction.


0

Response Number 7
Name: Razor2.3
Date: August 6, 2008 at 15:30:13 Pacific
Reply:

I did change part of it using Razor's correction.
Which is funny, because I don't remember posting code.

When I try to run it, I get "Microsoft VBScript Compilation Error: Expected Statement."
I'm not getting an error. Check your copy/paste.


0

Response Number 8
Name: ghostdog
Date: August 6, 2008 at 18:22:59 Pacific
Reply:

you should post what you have.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch file: rename file based on fs

Move a XML file based on content www.computing.net/answers/programming/move-a-xml-file-based-on-content/18945.html

Deleting files based on Date www.computing.net/answers/programming/deleting-files-based-on-date/15215.html

dos copy files based on filename www.computing.net/answers/programming/dos-copy-files-based-on-filename/17353.html