DPChallenge: A Digital Photography Contest You are not logged in. (log in or register
 

DPChallenge Forums >> General Discussion >> I need a VB Script
Pages:  
Showing posts 1 - 12 of 12, (reverse)
AuthorThread
01/08/2010 12:18:33 PM · #1
I had a VB Script that someone gave me a long time ago that would allow me to drop the file into a folder and run the script thus creating a .txt file in the same folder with all the file names and extensions.

Does anyone have anything like this or are there any VB people out there that could write this script for me?

Ultimately I have a folder with hundreds of file names and I need to list all the files, how can I do this?
01/08/2010 12:30:09 PM · #2
okay I found a script that works somewhat...

It prints to the printer, Can anyone fix this script to make it print the files into notepad for me???

@echo off
dir %1 /-p /o:gn > "%temp%\Listing"
start /w notepad /p "%temp%\Listing"
del "%temp%\Listing"
exit

01/08/2010 12:41:47 PM · #3
okay by removing the /p I am able to get the paste into notepad but the CMD screen is still up. How can I close that screen?
01/08/2010 01:01:40 PM · #4
the command window closes when you close the notepad window.
If you just want to put a directory listing in a Listing.txt file, then the following .bat file will work.

@echo off
dir %1 /-p /o:gn > ".\Listing.txt"
exit

The "." before "\Listing.txt" means put the file in the current directory.
01/08/2010 01:13:09 PM · #5
If you really want the vbscript version instead of just batch file then put the following in a .vbs file.

set ofs = CreateObject("Scripting.FileSystemObject")
Base = ofs.GetParentFolderName(wscript.ScriptFullName)
set otslisting = ofs.CreateTextFile(Base &"\listing.txt",1)
set ofolder = ofs.GetFolder(Base)
for each ofile in ofolder.files
otslisting.writeline ofile.name
next
otslisting.close
set otslisting = nothing
set ofile = nothing
set ofolder = nothing
set ofs = nothing

wscript.echo "Directory listing complete."
01/08/2010 01:17:24 PM · #6
Originally posted by shanksware:

If you really want the vbscript version instead of just batch file then put the following in a .vbs file.



Awesome, Thanks a million...


01/08/2010 01:21:42 PM · #7
The plus side of the batch file is that I can now right click on the folder and choose print directory by following some instructions that I found on a microsoft's site.

I really like it because I don't need to move the file around. Can I set up the VBscript to work the same way?

And now that I have the ability to do this I also like that it doesn't create another file in the folder, can you modify it so it just opens and if I need to save it I can just do that from Notepads screen?

Message edited by author 2010-01-08 13:23:36.
01/08/2010 02:37:12 PM · #8
Ouch
So, you want to be able to right-click a directory and choose something like "Create File Listing" and have it run a vbscript program that opens a listing in notepad. The following is the vbscript to do that task. It lists the subfolders in the folder first, and then the files.

Set oShell = WScript.CreateObject("WScript.Shell")
oShell.Run "Notepad.exe"
Do Until Success = True
Success = oShell.AppActivate("Untitled - Notepad")
Wscript.Sleep 1000
Loop

set ofs = CreateObject("Scripting.FileSystemObject")
if wscript.arguments.count > 0 then
sfoldername = ""
for i = 1 to wscript.arguments.count
sfoldername = sfoldername &wscript.arguments(i-1) &" "
next
Base = sfoldername
else
Base = ofs.GetParentFolderName(wscript.ScriptFullName)
end if

set ofolder = ofs.GetFolder(Base)
oShell.SendKeys "Folders:" &vbcr
for each osubfolder in ofolder.subfolders
oShell.SendKeys osubfolder.name &vbcr
next

oShell.SendKeys vbcr &"Files:" &vbcr
for each ofile in ofolder.files
oShell.SendKeys ofile.name &vbcr
next

set osubfolder = nothing
set ofile = nothing
set ofolder = nothing
set ofs = nothing
set oShell = nothing

wscript.echo "Directory listing complete."

To hook it up to the right-click menu, follow the instructions on this page. In the "New Action" dialog in step two, you have to use the syntax for running the vbscript program. That would be wscript.exe or csript.exe and the program name.
Example:
you put the listing.vbs program in Program Files\Utilities
you would put in the dialog box - wscript.exe "C:\Program Files\Utilities\listing.vbs"

If you already have a right-click menu enabled, then you need to edit the registry to change the functionality.
You would find the entry to modify in:
HKEY_CLASSES_ROOT\Folder\shell\whateveryounamedyourcommand\command

EDIT:
fixed problem with folders with spaces in the folder name
ex: Documents and Settings

Message edited by author 2010-01-08 14:53:01.
01/08/2010 03:34:19 PM · #9
When I run this script I get a small bug, here is the output from the script:

Files:
DSC_6835.NEF
DSC_6836.NEF
DSC_^*$)>NEF
DSC-6841.NEF
DSc_6859.NEF
dSC_6860.NEF
DSC_6861.nEF

dSC_6862.NEF
DSC_6863.nEF
dSC_6864.NEF
DSC_6865.NEF
DSC_6866.NEF
DSDSC_6875.NEF
DSC_6876.NEF
DSC_6907.NEF
view files.vbs

By the way I really do appreciate you helping me with this.

Message edited by author 2010-01-08 15:35:08.
01/08/2010 03:42:12 PM · #10
Probably has more to do with using sendkeys than anything. That can happen sometimes. It's really a clunky way of automating things. If you were ok with always creating a file instead of just having it show up in notepad, then it would probably work more consistently.

01/08/2010 03:53:58 PM · #11
pm'ed you
01/08/2010 05:14:17 PM · #12
Originally posted by shanksware:

pm'ed you


Got it thanks
Pages:  
Current Server Time: 08/24/2025 07:20:10 PM

Please log in or register to post to the forums.


Home - Challenges - Community - League - Photos - Cameras - Lenses - Learn - Help - Terms of Use - Privacy - Top ^
DPChallenge, and website content and design, Copyright © 2001-2025 Challenging Technologies, LLC.
All digital photo copyrights belong to the photographers and may not be used without permission.
Current Server Time: 08/24/2025 07:20:10 PM EDT.