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
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)
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
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
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
Summary: Is it possible to move a file based on content. I have a directory that each day is filled up with a few hundred XML files. I would like to move the files to certain directories based on what is in th...
Summary: I need had rename files with the date and then move them to a particular foder. I have done the renaming and moving thing successfully but now i also need to delete files in tht particular folder bas...
Summary: Hi I would like to create a batch script which should pickup files from a share and then distribute them to different folders based on the filename. Filename is like str1_str2_str3.dat The files shoul...