Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm a Mac user, but I need to write a script on Windows, and I'm not sure how I should go about that.

Here's the scenario:

Someone adds photos to a USB drive. The drive is then inserted into a digital picture frame.

In order for the photos to autoplay, a 'playlist.asb' file must be present on the drive. I want to create a script that can be clicked on and executed to auto create the playlist file based on the image files added to the USB. The script would do something like this:

  1. Check if there are images in the 'slideshow' folder.
  2. Check if file called 'playlist.alb' exists, if not create it. If so, overwrite it.
  3. Loop through available images.
  4. Add each image name and extension on a new line.
  5. Save (and overwrite any existing playlist file) and exit.

I'm comfortable with AppleScript for Macs, but I'm not sure if a Windows equivalent would make sense, or if some kind of command line script would work better.

Any help is greatly appreciated.

share|improve this question

closed as off-topic by whatsisname, user61852, Glenn Nelson, Doc Brown, Bobson Dec 19 '13 at 20:37

  • This question does not appear to be about software development within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

    
It's hard to say what you need because its going to depend on what that .asb file looks like. There's certainly no shortage of scripting or programming languages for Windows. Also, is this something meant for YOU to run, or the end customer? –  GrandmasterB Dec 19 '13 at 17:47
    
What programming language are you using? For example, with Python you can develop for both platforms at once. –  Benjamin Gruenbaum Dec 19 '13 at 17:47
1  
I think this will have to be a batch file. The playlist.asb file will simply be a list of image files present on the USB drive (in the slideshow folder). This is meant for the digital picture frame user. Once they add their photos to the USB drive, they can execute this script to create the playlist file needed to show the images in the frame. I hope that makes sense. –  joshlawler7 Dec 19 '13 at 18:14
    
Using a 'regular' language like C++, C#, etc will get the job done far faster than using any of the windows scripting languages. –  whatsisname Dec 19 '13 at 18:26
    
@whatsisname Have you ever written in PowerShell before? I wrote an installer in under 200 lines that has so much more functionality than I could ever build in C# in an equivalent amount of code. I never would have believed it until I coded it myself, but I've seen the light now. –  mgw854 Dec 19 '13 at 20:32
show 2 more comments

3 Answers 3

up vote 1 down vote accepted

@user61852 is on the right track, but his solution has the drawback that it will not work with a different drive letter. And you don't know the drive letter beforehand. Everytime you insert the usb stick, it may get a different drive letter assigned to.

As a solution, one should put the script directly in the main folder of the usb stick itself, and add cd /d %~d0%~p0 to the first line. This makes the usb home directory the current directory. Then, you can leave out the letter afterwards. So the script should look like this:

cd /d %~d0%~p0
dir /b \slideshow\*.jpg >\slideshow\playlist.alb
share|improve this answer
    
I think this should do it. Thanks! –  joshlawler7 Dec 19 '13 at 20:27
add comment

Assuming flashdrive will allways be mapped to, e.g., G: letter, and all images are jpgs, then this should work:

echo. > g:\slideshow\playlist.alb
dir /b g:\slideshow\*.jpg >> g:\slideshow\playlist.alb

Create a file with the .bat extension with that instruction in it.

If no jpg file is found, an empty playlist will be created which should yield the same result as having no playlist at all.

The /b switch is to prevent boilerplate text, file sizes, dates, etc, from being dumped into the file. The echo command with a dot at the end (no space) is not a typo.

Update:

First line generates a file with a blank line in it. In the second line, ">" is changed to ">>" to append at the end of such a file rather than overwriting it.

share|improve this answer
    
Thanks - this is what I was looking for. @Doc Brown took it a step further to anticipate changing drives. –  joshlawler7 Dec 19 '13 at 20:29
    
@joshlawler7 I updated the answer. –  user61852 Dec 19 '13 at 20:43
add comment

The scope and scale here isn't well defined in the question, so I'm answering this assuming the USB drive is being shipped with the photo frame, and the whole thing is meant for the end user to use.

If thats the case, the route I'd take would be to make an executable that runs automatically when the USB drive is plugged in (as set in an autorun.inf file). That program would provide an interface prompting the user to drag/drop files into it. As the files are added, that program would create the .asb file automatically. If the user adds files to the USB drive manually, you can have them launch the program which will generate the .asb file.

I would not rely on the customer knowing what a batch file is, or even rely on them reading instructions.

The technology you'd use for creating this would essentially be any programming language capable of generating a stand-alone Windows executable.

share|improve this answer
    
I apologize for not defining scope and scale very well, the scenario here is a bit unusual. My team is preparing to send these displays (and usb sticks) to a marketing team who will update the photos occasionally. They're not customers, and the updates are fairly sparse, so I don't think clicking a batch file is a bad idea, though not entirely fool proof I admit. Thanks for the detailed response. –  joshlawler7 Dec 19 '13 at 20:15
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.