Write me a batch file please?


M

Metspitzer

Write me a batch file please?

I have two folders with videos. I would like a batch file that prints
the filenames (with or without extension) to a text file and then
sorts the list.
 
Ad

Advertisements

G

Gene E. Bloch

Write me a batch file please?

I have two folders with videos. I would like a batch file that prints
the filenames (with or without extension) to a text file and then
sorts the list.
Sorts the list by file length? Date created? Modified? File-name
extension?


You don't need a batch file, just one command:

dir /B /O:N > mylist.txt

This will list just the names with extensions, sorted by name.

Try opening up a command window and typing dir /?
(unless you are unwilling to learn something). This will show a list of
the available arguments, including the other sort options.
 
N

Nil

Write me a batch file please?

I have two folders with videos. I would like a batch file that
prints the filenames (with or without extension) to a text file
and then sorts the list.
What have you tried so far?
 
D

Dave \Crash\ Dummy

Gene said:
Sorts the list by file length? Date created? Modified? File-name
extension?


You don't need a batch file, just one command:

dir /B /O:N > mylist.txt

This will list just the names with extensions, sorted by name.

Try opening up a command window and typing dir /? (unless you are
unwilling to learn something). This will show a list of the available
arguments, including the other sort options.
As I understand it, the OP wants to combine the two directory listings
into a single sorted file list. I could do it with a script, but I don't
know how to do it with a batch file.
 
P

Paul

Metspitzer said:
Write me a batch file please?

I have two folders with videos. I would like a batch file that prints
the filenames (with or without extension) to a text file and then
sorts the list.
Is this for the purpose of detecting duplicates ?

http://download.cnet.com/Auslogics-Duplicate-File-Finder/3000-2248_4-10964299.html

There's a better picture of the program, on this page.

http://www.auslogics.com/en/software/duplicate-file-finder/

Just be careful there are no toolbars hiding in the download.
The download is supposed to be a zip, with hopefully, just
the program itself in there.

Paul
 
W

Wolf K

As I understand it, the OP wants to combine the two directory listings
into a single sorted file list. I could do it with a script, but I don't
know how to do it with a batch file.
A script is a batch file, isn't it? Or vice versa. ;-)
 
G

Gene E. Bloch

As I understand it, the OP wants to combine the two directory listings
into a single sorted file list. I could do it with a script, but I don't
know how to do it with a batch file.
OMG! Then he'd be forced to learn about ">>" and about the sort program!

Actually, I'd recommend awk, but I'd have to relearn it after an absence
of a couple of decades :)

The sort program doesn't look that helpful, either.

To Metspitzer - if you have & are familiar with Excel or another
spreadsheet program, the easiest thing to do might be to use my
suggestion in two directories to get two files, then import them into
the spreadsheet program, then sort in that program.
 
C

Char Jackson

As I understand it, the OP wants to combine the two directory listings
into a single sorted file list. I could do it with a script, but I don't
know how to do it with a batch file.
As others have said, a script and batch are essentially the same
thing, depending on the scripting language you prefer to use.

I'd probably do something like this:

REM combine and sort two directory lists
dir drive:\dir1 /B /O:N > mylist.txt
dir drive:\dir2 /B /O:N >> mylist.txt
sort mylist.txt /o mylist-sorted.txt

Just replace the "drive:\dir" stuff with the actual directories you
want to work with.

You can add as many directories as you like before you do the sort.
 
G

Gene Wirchenko

[snip]
I'd probably do something like this:
A few clarifying points:
REM combine and sort two directory lists
dir drive:\dir1 /B /O:N > mylist.txt
^
One ">" means to create the output file.
dir drive:\dir2 /B /O:N >> mylist.txt
^^
Two ">" means to append to the file if it already exists. The
file is created if it did not already exist.

The "/O:N" are not needed since the list is going to get sorted
by sort anyway.
sort mylist.txt /o mylist-sorted.txt

Just replace the "drive:\dir" stuff with the actual directories you
want to work with.

You can add as many directories as you like before you do the sort.
Use ">>" for the second and on dir commands.

Sincerely,

Gene Wirchenko
 
C

Char Jackson

[snip]
I'd probably do something like this:
A few clarifying points:
REM combine and sort two directory lists
dir drive:\dir1 /B /O:N > mylist.txt
^
One ">" means to create the output file.
dir drive:\dir2 /B /O:N >> mylist.txt
^^
Two ">" means to append to the file if it already exists. The
file is created if it did not already exist.

The "/O:N" are not needed since the list is going to get sorted
by sort anyway.
sort mylist.txt /o mylist-sorted.txt

Just replace the "drive:\dir" stuff with the actual directories you
want to work with.

You can add as many directories as you like before you do the sort.
Use ">>" for the second and on dir commands.
Thanks, Gene. I'm already aware of your clarifications but perhaps
someone else will get something out of them.
 
P

Paul

Paul said:
Is this for the purpose of detecting duplicates ?

http://download.cnet.com/Auslogics-Duplicate-File-Finder/3000-2248_4-10964299.html


There's a better picture of the program, on this page.

http://www.auslogics.com/en/software/duplicate-file-finder/

Just be careful there are no toolbars hiding in the download.
The download is supposed to be a zip, with hopefully, just
the program itself in there.

Paul
I was only half-joking about the toolbar.

I downloaded the program, and it was about 6MB in size. Which
seems a bit too big for a function that simple. With all the
graphical goodness, maybe 300KB would be more reasonable.

I got more info from majorgeeks.

http://www.majorgeeks.com/download6187.html?2012-08-10

"Limitations: Offers to install branded toolbar."

The Interwebs are filled with limitless humor.

I wonder if somewhere, in a parallel universe, they
don't have toolbars. Man, I'd love to live there...

Paul
 
N

Nil

I like the way you think. ;-)
Surely he tried to write his own and ran into a problem, right? Nobody
would have the balls to ask a bunch of strangers to do all the work for
them without having trying to do it themselves... would they???
 
C

Char Jackson

Surely he tried to write his own and ran into a problem, right? Nobody
would have the balls to ask a bunch of strangers to do all the work for
them without having trying to do it themselves... would they???
You are so right. My thoughts, exactly. ;-)

This time, though, we just may have an exception to the rule.
 
G

Gene Wirchenko

[snip]
Thanks, Gene. I'm already aware of your clarifications but perhaps
someone else will get something out of them.
I figured OP would. Sometimes, we forget how mysterious it was.

(I have the mystery hitting me in other areas.)

Sincerely,

Gene Wirchenko
 
P

Paul

Metspitzer said:
Write me a batch file please?

I have two folders with videos. I would like a batch file that prints
the filenames (with or without extension) to a text file and then
sorts the list.
Copy the following into Notepad, and save as "listdir.vbs".

***********************************************************

' // Script to list files.
' // List is tab separated.
' // Based on someone elses script, with slight changes.
' // Output looks like this. (Size <tab> Date <tab> Path)
' //
' // 32964 1/19/2012 1:06:32 AM C:\test.txt
' //
' // This program has no command line arguments. You enter the
' // topDir as a string in the line below. That's where it'll start
' // scanning. The output always goes to ScriptOutput1.txt . Change
' // the name to something you like.
' //
' // Program has no error handling. I just changed another script, to make this one.
' //
' // In the Command Prompt window, enter "listdir" as the command...
' // listdir.vbs should be in your current working directory, do the DOS shell
' // can find it.

Dim objFSO
Dim tab
tab=chr(9)

topDir = "C:\Downloads\"
set objFSO = CreateObject("Scripting.FileSystemObject")

' Create text file to store output data
' When you launch this in MSDOS window, file will be created in current working directory.

Set OutputFile = objFSO.CreateTextFile("ScriptOutput1.txt", True)

Set objFolder = objFSO.GetFolder(topDir)
Set colFiles = objFolder.Files
Set colFolders = objFolder.SubFolders

For Each objFile in colFiles
Outputfile.write(objFile.size)
Outputfile.write(tab)
Outputfile.write(objFile.DateLastModified)
Outputfile.write(tab)
Outputfile.writeLine(objFile.Path)
Next

' Call a separate subroutine, to output file contents of subfolders

For Each objSubFolder In colFolders
ScanSubFolders(objSubFolder)
Next

' Close text file
OutputFile.Close
' Program ends here...

' // **************************************
Sub scanSubFolders(objFolder)

Set colFiles = objFolder.Files
Set colFolders = objFolder.SubFolders

For Each objFile in colFiles
Outputfile.write(objFile.size)
Outputfile.write(tab)
Outputfile.write(objFile.DateLastModified)
Outputfile.write(tab)
Outputfile.writeLine(objFile.Path)
Next

For Each objSubFolder In colFolders
ScanSubFolders(objSubFolder)
Next

End Sub

***********************************************************

The output from the script, is tab separated. Import the
text file created from the script, with a spreadsheet
program, and you can do the sorting from there. The tab
separated format, is intended to make it easier to import
into a spreadsheet.

HTH,
Paul
 
C

Char Jackson

Copy the following into Notepad, and save as "listdir.vbs".

***********************************************************

' // Script to list files.
' // List is tab separated.
' // Based on someone elses script, with slight changes.
' // Output looks like this. (Size <tab> Date <tab> Path)
' //
' // 32964 1/19/2012 1:06:32 AM C:\test.txt
' //
' // This program has no command line arguments. You enter the
' // topDir as a string in the line below. That's where it'll start
' // scanning. The output always goes to ScriptOutput1.txt . Change
' // the name to something you like.
' //
' // Program has no error handling. I just changed another script, to make this one.
' //
' // In the Command Prompt window, enter "listdir" as the command...
' // listdir.vbs should be in your current working directory, do the DOS shell
' // can find it.

Dim objFSO
Dim tab
tab=chr(9)

topDir = "C:\Downloads\"
set objFSO = CreateObject("Scripting.FileSystemObject")

' Create text file to store output data
' When you launch this in MSDOS window, file will be created in current working directory.

Set OutputFile = objFSO.CreateTextFile("ScriptOutput1.txt", True)

Set objFolder = objFSO.GetFolder(topDir)
Set colFiles = objFolder.Files
Set colFolders = objFolder.SubFolders

For Each objFile in colFiles
Outputfile.write(objFile.size)
Outputfile.write(tab)
Outputfile.write(objFile.DateLastModified)
Outputfile.write(tab)
Outputfile.writeLine(objFile.Path)
Next

' Call a separate subroutine, to output file contents of subfolders

For Each objSubFolder In colFolders
ScanSubFolders(objSubFolder)
Next

' Close text file
OutputFile.Close
' Program ends here...

' // **************************************
Sub scanSubFolders(objFolder)

Set colFiles = objFolder.Files
Set colFolders = objFolder.SubFolders

For Each objFile in colFiles
Outputfile.write(objFile.size)
Outputfile.write(tab)
Outputfile.write(objFile.DateLastModified)
Outputfile.write(tab)
Outputfile.writeLine(objFile.Path)
Next

For Each objSubFolder In colFolders
ScanSubFolders(objSubFolder)
Next

End Sub

***********************************************************

The output from the script, is tab separated. Import the
text file created from the script, with a spreadsheet
program, and you can do the sorting from there. The tab
separated format, is intended to make it easier to import
into a spreadsheet.
Wow. The 3-line batch file I posted earlier (using Gene Bloch's code)
really puts this to shame, and that's before you consider the fact
that it doesn't require a second run nor a third-party program to
manage the sorting.
 
P

Paul

Char said:
Wow. The 3-line batch file I posted earlier (using Gene Bloch's code)
really puts this to shame, and that's before you consider the fact
that it doesn't require a second run nor a third-party program to
manage the sorting.
!) I didn't write this from scratch.
It's someone else's script.
2) I don't have a programming reference for this language.
I don't know if it has a sort library.
3) The script was lying around in a directory I did some
other stuff in, and I just dug it out.
4) It's meant to demonstrate to the OP, you can find programming
examples lying around, and do stuff with them.

Paul
 
Ad

Advertisements

C

Char Jackson

!) I didn't write this from scratch.
It's someone else's script.
2) I don't have a programming reference for this language.
I don't know if it has a sort library.
3) The script was lying around in a directory I did some
other stuff in, and I just dug it out.
4) It's meant to demonstrate to the OP, you can find programming
examples lying around, and do stuff with them.
Gotcha. Thanks. Still, it's embarrassingly complex for such a simple
task.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top