Wednesday, 23 July 2008

Recursively Listing Files In A Directory And Adding Their Names To A Text File In Visual Basic .NET

Recently asked on Yahoo! Answers:

Reading file names in VB.NET?
I am making a program that I will use to read files in a particular folder and put those file names into a text file. How can I do this?

This is actually pretty easy to do in VB.NET, and there are several other examples on the Web. But it’s been a while since I’ve written anything on VB.NET, so I figured I would do this one.

I will accomplish this task with two subroutines. The first is a recursive subroutine that accepts a file path (e.g., C:pathtosomedirectory), scans all its subdirectories for files, and returns the name of each file to a second subroutine.

That second subroutine adds the passed file name to a text file.

Continue reading: Recursively Listing Files In A Directory And Adding Their Names To A Text File In Visual Basic .NET »

Tuesday, 1 January 2008

A Windows Shell Script To Automatically Rename And Move Images To A New Folder

Recently asked on Yahoo! Answers:

How do I set Windows XP to rename same named files when in same directory?
I’m putting thousands of images and other files in the same folder so that I can sort from that folder, I want to keep all the versions that I may have the same file name with different names when I put them in that folder. If I can I would also like to leave the () out of the new rename. I’ve seen other computers that do the renaming automatically, this would save me time from the current setting in which it asks with each file if I want to overwrite it and if it doesn’t overwrite it just leaves the file where it was before without putting it in!

This is simple enough to do if you have a little knowledge of VBScript; in this case, as it pertains to the Windows Scripting Host (or whatever Microsoft calls it these days).

Basically, a few lines of VBS can quickly get all the files in a directory, maintain their current sort order, rename them to be 100 percent unique, and move those files from whatever directory they are currently in to wherever we want them to go.

Let’s do it. As always, code you can download appears at the end of this listing.

Continue reading: A Windows Shell Script To Automatically Rename And Move Images To A New Folder »

Tuesday, 3 July 2007

Displaying A Random Image From A Directory Via PHP, Part 2

In a recent blog post about randomly displaying an image from a directory via PHP and its built-in image and filesystem functions, I promised to expand upon the answer I had given to demonstrate some other cool filesystem tricks.

It’s about time I made good on that promise.

We’ll start by showing how to display a random image on a Web page, rather than forging the PHP to represent itself as an image; and we’ll also make a thumbnail gallery of all the images in the folder, which even shows the active image.

Continue reading: Displaying A Random Image From A Directory Via PHP, Part 2 »

Wednesday, 27 June 2007

Displaying A Random Image From A Directory Via PHP

Recently asked on Yahoo! Answers:

How would one code a rotating image (using PHP) that can be hosted on Geocities Pro for, say, a forum?

In the past, I’ve been able to host a rotating image using another method by naming a folder ‘something.png’ to fool a forum into thinking the folder is a picture and it reads the index.php file, which in turn pulls up one of the images I have coded. Now that I’m on Geocities Pro, I cannot make such a folder but would like to still use my rotating image. Is there another way I can code this and still be able to use it with forum BBCode?

Basically, this questioner wants a PHP script to look through the contents of an image directory, randomly select one of the images in that directory, and pass the script itself off as the image.

That’s fairly simple to do in PHP, but it does require a number of steps and a few tricks to overcome some limitations of PHP’s built-in filesystem functions.

This question also gives me a chance to explain working with the filesystem in PHP, and to demonstrate how loops and arrays can be used to produce some really neat results, so I’ll expand on that in a follow-up post.

As always, a working demo and source code will be available for download at the end of this article.

Continue reading: Displaying A Random Image From A Directory Via PHP »

Sunday, 3 December 2006

An ASP.NET 2.0 Script To Share Files Among Users

Recently asked on Yahoo! Answers:

How could I enable user to upload and download file from server using asp.net 2?

How could I enable a user to upload file to the server and then view link to download this file from the server to anthor user i when he enters the site using ASP.NET 2?

The problems here could be handled very easily simply by using the built-in FileUpload class and the DirectoryInfo / FileInfo classes to display the files in the targeted directory.

So, let’s run that simple code today.

Continue reading: An ASP.NET 2.0 Script To Share Files Among Users »