1.

Solve : if not exist bad-command?

Answer»

Hi All,

Need to create a batch job to perform the following:

  • Check if a file/multiple files exist/s
  • Size of file > 1kb
  • Creation time of file < 24hrs old

Not sure how crude such a script should be.
Any suggestions?

Cheers,
CameronHomework Hi Dusty,

Actually no (but to be that young again!)
Task was given to me by the boss, just to interupt my PCI work.
When I posted the query; thought sadly that the question might be seen as some FORM of homework.
I've not done work with timestamps or filesizes before, hence the question. And I've had my hand out of DOS scripting for a little while now.

Any help/direction appreciated.

Cheers,
CameronHeres a VBScript that will do the job
open note, copy and paste the script below, save as something.vbs
open command prompt, type: cscript something.vbs filename
where the filename is the file you want to check. This needs to include the full path.

If you want to check mulitple files, you could create a batch file which calls something.vbs for as many files as you need


'-----------------------------------------------------
Set objArgs = WScript.Arguments
If WScript.Arguments.Count < 1 Then
wscript.echo "Usage: cscript scriptname.vbs drive:\path\filename"
wscript.quit
Else
StrFile = wscript.arguments.item(0)
End if

Dim fsoFile
Set fsoFile = CreateObject("Scripting.FileSystemObject")

If fsofile.FileExists(StrFile) Then
Set objFile = fsoFile.GetFile(StrFile)

sName = objFile.Name
sCreated = objFile.DateCreated
sSize = objFile.Size

If sSize > 1024 Then'Check Size
Age = DateDiff("d", sCreated, Date())'Get Age difference
If Age > 1 Then 'Check date is greater than 1 day
wscript.echo objFile.Name
wscript.echo objFile.Size
wscript.echo objFile.DateCreated
End If
Else
wscript.echo "Not met the criteria"

End If
End If

set objfile = nothing
set fsofile = nothing
'-----------------------------------------------Many thanks TheManFrom,

Spent a few hours stumbling with the old scripting last night - sad when you forget so much of it.
Seems that to perform the task purely as a MSDOS/NT script would be a painful challenge.
Is VBScripting becoming (or is now) more the MAINSTREAM ?

Cheers,
CameronYes I think VBS is the way forward for admin tasks. DOS is GREAT but has its limitations which is where I think VBS comes in handy
Anyways GLAD I could help.is there a particular program you need to write VBscript? My school has "Object oriented Turing"
but I want to write this at home, and the computer I use at home, doesn't have internet. . .
can I just use notepad for Visual Basic? is there any ONLINE tutorials? (I forget the strings things. . .
eg.


var:String
var:name
var:pass
cls
LOOP
put "what is your username"
get name
put "what is your password
get pass
exit when pass = "wood" or pass = name
end loop

that is Turing (except with a fault in the "Var" block at top. . .
I can't seem to get that to work right. . . anyway can you write stuff like this in
NOTEPAD?? (on a 10yr old computer?? with no internet. .)

Please, these questions are important to me lol. . .VBScript is like a cut down version of visual basic and has the advantage of like dos batch file, you can simply open a text editor like notepad, add your script and instead of .bat, save the file as .vbs.
Then to run the program, from the command prompt (Start->Run->cmd) simply type: cscript name.vbs
You do no need internet however it would be handy for tutorials to learn from

It doesnt matter how old your computer is as long as you have at least windows 95 (I think thats the minimum)

As of your example above, in vbs you do not need to declare your variable (although it is best practise to always declare them )

The above in vbs would look somthing like

Code: [Select]DO
Pass=""
pass = InputBox("Please enter your password")
Loop Until Pass="wood" or pass="name"


Discussion

No Comment Found