Computer Hope
Microsoft => Microsoft DOS => Topic started by: nzidiot on May 08, 2009, 09:59:04 PM
-
Hi
For an assignment i have, i have to, in a batch file, List all text files whose names are seven characters long on the whole C: Drive - make the listing output in wide format and then output the listing to a file.
I know how to save the results to a file
> (file name)
I know the command for listing files on the C Drive
DIR C:\ /S /W .txt
The /s being to include sub folders in search and the /w being display the listing in wide format. The .txt being the file format i want to search for.
The command im stuck with is listing only 7 character files. Please help
Thanks
-
dir/b c:\*.txt|findstr/r /i "^.......\.txt"
-
if your assignment is not restricted to batch: here's a vbscript. it assumes total length of filename including extension.
Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder = "c:\"
Set objFolder = objFS.GetFolder(strFolder)
Sub ScanDir (objFolder)
For Each strDir In objFolder.SubFolders
ScanDir(strDir)
Next
For Each strFile In objFolder.Files
If Len(strFile.Name) = 7 And objFS.GetExtensionName(strFile.Name) = "txt" Then
WScript.Echo "do something here"
End If
Next
End Sub
ScanDir objFolder
-
dir/b c:\*.txt|findstr/r /i "^.......\.txt"
its whole c drive, therefore needs /s. after that, the regular expression for findstr will be different.
-
if your assignment is not restricted to batch
gh0stg0g74,
I think you missed the part of the original post that said the assignment was in batch
For an assignment i have, i have to, in a batch file,
-
gh0stg0g74,
I think you missed the part of the original post that said the assignment was in batch
He didn't say it should be in "pure batch" either. anyway, to choose to use my solution or not, is entirely up to OP, so i think you shouldn't worry too much about how or what i post (as long as it solves the problem)
-
its whole c drive, therefore needs /s. after that, the regular expression for findstr will be different.
for whole c drive, longer code:
dir/b/s *.txt|findstr/rei "\\[^\\][^\\][^\\][^\\][^\\][^\\][^\\]\.txt"
gh0stg0g74,
I think you missed the part of the original post that said the assignment was in batch
::) oh no, it's for assignment??? :(
-
He didn't say it should be in "pure batch" either.
he didn't say the answers should be written in Sanskrit either.
For an assignment i have, i have to, in a batch file
That is so ambiguous! The words "a batch file"could mean anything! Like "any scripting language that I can brag about knowing a bit about".
-
::) oh no, it's for assignment??? :(
doesn't matter as there is still something missing in your solution, so let OP find out for himself. still alright i guess:)
-
he didn't say the answers should be written in Sanskrit either.
huh ?
That is so ambiguous! The words "a batch file"could mean anything! Like "any scripting language that I can brag about knowing a bit about".
isn't this a fact already well known? unless specifically mentioned that pure batch is needed, a batch file can mean anything.
-
a batch file can mean anything.
That is a laughably idiotic remark.
You don't give up, do you?
-
huh ?
It's a lame excuse to say that anything not specifically excluded is allowed.
-
That is a laughably idiotic remark
you don't think deep , do you? you should watch your language, you are not a school kid anymore, are you?
-
It's a lame excuse to say that anything not specifically excluded is allowed.
that's not up to you to decide.
-
that's not up to you to decide.
Yes it is. I just appointed myself.
-
(as long as it solves the problem)
How is giving him a solution in VBScript going to solve his problem when he needs it in batch?
-
How is giving him a solution in VBScript going to solve his problem when he needs it in batch?
if you don't like my post, why don't you report to the moderator? if not, why should you care ?
@echo off
cscript /nologo myscript.vbs
save the above as myscript.bat, and there's your batch. anything wrong?
-
if you don't like my post, why don't you report to the moderator? if not, why should you care ?
Pendejo.
save the above as myscript.bat, and there's your batch. anything wrong?
Plenty. You sure are getting like a troll.
-
Pendejo.
Plenty. You sure are getting like a troll.
you look more like a troll to me.
-
Plenty. You sure are getting like a troll.
so can you tell what's wrong? if not, stfu
-
if you don't like my post, why don't you report to the moderator?
I have now...
-
I have now...
good. on what grounds?
-
Ah, "stfu". ::)
-
Ah, "stfu". ::)
good. since you have free time, how about reporting post #10 and #17 for me. those 2 posts really piss me off and rude , so i think its only fair you report them as well.
-
Nzidiot,
Let me apologize to you for post that aren't helping you with your problem. Normally the people that post here are able to give you good guidance with out all the fuss.
Sorry for any confusion or frustration caused on my part.
-
good. since you have free time, how about reporting post #10 and #17 for me. those 2 posts really piss me off and rude , so i think its only fair you report them as well.
Free time? So what exactly are you doing on here? And I would report those other 2 posts if I agreed with you, but I don't. You're missing the point entirely. I don't understand how you don't see that the OP want's batch, and yet you still give it in VBS.
-
Free time? So what exactly are you doing on here? And I would report those other 2 posts if I agreed with you, but I don't. You're missing the point entirely. I don't understand how you don't see that the OP want's batch, and yet you still give it in VBS.
how do you define batch? give me a real answer
-
I have now...
me too.
-
Quote:
Now now boys calm down :)
-
me too.
me too.
-
how do you define batch? give me a real answer
me too.
Grow up for God's sake.
-
Grow up for God's sake.
you can't answer me? then where's is that justification that what i do is wrong?
-
you can't answer me? then where's is that justification that what i do is wrong?
Exactly I can't answer you, because I don't know batch. But I do know how to run a forum.
-
how do you define batch? give me a real answer
In DOS, OS/2, and Microsoft Windows, a batch file is a text file containing a series of commands intended to be executed by the command interpreter. The OP mentioned a C: drive, so it's a pretty fair bet he or she is using one of these. It is also a fair bet, since the OP appears to be seeking the solution to a school assignment, and from a careful reading of the question, that the desired outcome is to demonstrate competence in using fairly simple features, such as command output redirection, DIR switches such as /W and /S and wildcards. I think the assignment is more likely to find files of 7 characters or less in the filename.
-
Exactly I can't answer you, because I don't know batch.
wow, you do not know batch, BUT you can tell what's right or wrong? gimme a break.
But I do know how to run a forum.
no you don't. If you are really running this forum, as in doing the administration/design etc..you would state clearly that anything other than batch are not allowed, only then I will not post in VBscript or any other languages i know.
-
Wow, a flood of topic reports...
Dias, Ghostdog, settle this elsewhere. That's what PMs are for.
Topic Closed. If anyone wants this reopened for any reason, please PM me.
Kpac is right in one thing. He doesn't go around trying to boost his post count with useless remarks.