

So for example, a file with the following name:Ģ021. To make things easier for myself and anyone else looking through these files, I rename them with the sent/received date (and a dash) at the front (in the format " YYYY.MM.DD.hhmm - " in 24 hour time) so that they automatically sort into chronological order when sorted by name. MSG files) into job folders for reference at a later time. Label that is just below and to the right of this text.As part of my job, I regularly have to save email correspondence (i.e. If you liked this article and want to see more from this author, please click the Yes button near the: String Object (Windows Scripting - JScript) That will make it easy to locate and retrieve a specific-day's files from the archive folder.ĭate Object (Windows Scripting - JScript) The point of using "normalized" dates (with two-digit month and two-digit day) is that they will always be displayed in the correct order when sorted. Just use a negative value as the first (and only) parameter. The JScript String.slice() method can be used to emulate the often-needed Right$()-type function of many programming languages (to extract from the end of the string). Take a look at the code that generates the "dating prefix." Note that I went to some trouble to ensure that the format would be YYYYMMDD that is, two digits for the month and two digits for the day. Instead, just hard-code a list of source filenames into the script. Also, if you need to drop the files more than once per day, you would want to add a time component to the renaming prefix.Īnd of course, if you do this same thing - for the exact same set of files - every day, then it would be silly to force your user to select and drag the files. For instance, that code will not work if you drop an entire folder on the icon. There are lots of ways to improve this and/or modify that script for more flexibility. Now, when you want to move the files to the archive folder, just use the Windows Explorer to select the files, drag them over the script icon, and drop them. JS for instance, DropHereToArchive.JS The desktop icon changes from a text document to a script document. Then rename that file with an extension of. Just create a text file on your desktop, and paste the above text into it.

- JScript utility to move files, and rename with a date component var sDestFolder= "F:\\Accounting\\ArchivedBackups\\" var oArgs= WScript.Arguments var oFSO= new ActiveXObject("Scripting.FileSystemObject") var oDt= new Date() var sRenPrefix= oDt.getFullYear() + ("0"+(oDt.getMonth()+1)).slice(-2) // 01 to 12 + ("0"+oDt.getDate()).slice(-2) // 01 to 31 + ("_") //- cycle through the filenames in the dropped selection for (var j= 0 j < oArgs.Count() j++ ) WScript.Echo( oArgs.Count()+" Files renamed and moved to ARCHIVE folder" ) There is no need to use the arcane batch-file syntax when the Windows Scripting Host (WSH) provides a choice of full-featured scripting languages and access to powerful tools such as the FileSystemObject object.Īnyway, I solved my client's problem with this simple JScript program: Obtaining the date as a usable string is a bit of a trick, as well.Īnyway, batch files are way obsolete. But I ran into a hassle when there are more than 9 files in the dropped group. BAT file icon and they end up as %1, %2, etc.

I first tried to write a complicated DOS batch file - you can use the Windows Explorer to drop files onto a. The solution is to move the files to the target folder, but rename each of them with an inserted date prefix, so that the new filenames will not collide with, or overwrite the older ones. The problem is that just dragging and dropping the files won't work - the "current" files would have the same names as the "archived" file. One of my clients had a specific need and requested that I write a program to handle it: Every day, he needs to move files from a "staging" directory to an "archive" directory. How to avoid the "Confirm File Replace" prompt.
