Windows: Add Copy-to and Move-to folder to context menu

digg del.icio.us TRACK TOP
By Eric Downing | Filed in OS, Windows | No comments yet.

I spend a lot of time copying and moving files between folders. More often than not, when I click on a file in Explorer, I want to copy or move it to another folder. That means I spend a good deal of time dragging files around or copying and pasting them.

But with a Registry entry, you can save yourself time: you can add Copy To Folder and Move To Folder options to the right-click context menu. When you choose one of the options from the menu, you get a dialog that will let you choose the location to copy or move the file to, and then send the file there.

To add the option, run the Registry Editor (regedit) and go to

HKEY_CLASSES_ROOTAllFilesystemObjectsshellexContextMenuHandlers.shellex

This tells you it’s a shell extension key that lets you customize the user shell or the interface. Create a new key called “Copy To”.

Set the value to

{C2FBB630-2971-11d1-A18C-00C04FD75D13}.

Create another new key called “Move To”. Set the value to

{C2FBB631-2971-11d1-A18C-00C04FD75D13}.

Exit the Registry.

The changes should take effect immediately. The Copy To Folder and Move To Folder options will appear. When you right-click on a file and choose one of the options, you’ll be able to move or copy the file using a dialog box like the

SQL: Get a list of dates

digg del.icio.us TRACK TOP
By Eric Downing | Filed in Programming, SQL | No comments yet.

So I didn’t have a table of dates set up, but I needed to get a list of dates going
back a certain number of days. I was looking at programming up a date function but
decided that a little SQL could do just what I wanted. I used the following query
to generate my list:

select (current_date-21) +s.a as date from generate_series(0,21) as s(A);

This returned a list of dates:

2012-06-01
2012-06-02
2012-06-03
2012-06-04
2012-06-05
2012-06-06
2012-06-07
2012-06-08
2012-06-09
2012-06-10
2012-06-11
2012-06-12
2012-06-13
2012-06-14
2012-06-15
2012-06-16
2012-06-17
2012-06-18
2012-06-19
2012-06-20
2012-06-21
2012-06-22

This dealt with end of month issues and end of year issues without having to generate a ton
of code to do the same thing.

Tags: ,

Here is my basic script for handling command line arguments in Python(pre version 2.7 when optparse
was deprecated). The optparse library is very useful in not only handling the command line
arguments, but setting up your help menu as well.

You will need to create an OptionParser and the usage argument lets you print the usage statement
for the script. Then you can add options, add groups for options or collect the left over
parameters as a secondary command or list of files. I use this method often as I create scripts
that help automate build processes.

#!/usr/bin/python

import sys, optparse

# This creates an OptionParser object with the usage string.
op = optparse.OptionParser(usage=" %prog [options]")
# This will add an option -m or --mode which takes sets the mode variable as
# True or False
op.add_option("-m","--mode",help="Specify the mode for the command", 
            action="store_true", dest="mode",default=False)
# This parses the options and places the selected options above in the _options
# object and the rest in arguments.
_options,arguments = op.parse_args()

# Checks if no arguments are passed and if so, runs the print_help method of 
# the OptionParser object
if len(sys.argv) == 1:
    op.print_help()

# This was just to show what happened when you did or didn't pass the
# --mode argument.
if  _options.mode:
    print "Mode is on"
else:
    print "Mode is off"

This method is currently deprecated as of version 2.7. I will write a follow-up post that uses
the newer argparse routine to highlight any differences.

Tags: ,

DOS: Capture return values from commands

digg del.icio.us TRACK TOP
By Eric Downing | Filed in Scripting, Utilities, Windows | No comments yet.

When I am writing build automation scripts, there are times that I have to insure that the previous command completed
with no errors. I have found that ERRORLEVEL gets filled in with the return value from a command.

dir %1

if (%ERRORLEVEL%) == (0) echo Found File: %1
if (%ERRORLEVEL%) == (1) echo Missing File: %1

So if you save the previous in a file and run the command with one (1) argument, it will display the output of the dir command
but also print either “Found file: ” or “Missing File: “.

Tags: ,

3DSMax: Remove background image

digg del.icio.us TRACK TOP
By Eric Downing | Filed in 3D, Software | No comments yet.

So in 3DSMax it is sometimes useful to insert a background image usually when you are modelling
something and using the background image as a guide. There is no easy way to remove it. You
can reassign another image or set it to not display the background image, but this can lead to
problems if the file is moved or removed as it is still linked to your max file.

MaxScript to the rescue! You can use the MaxScript Listener(F11) to type in the following to
clear the background filename:

backgroundimagefilename=""

This will clear the entry for the filename. I have noticed that you do need to exit 3DSMax to
fully make the change complete.

Tags: ,

Python: error when using the input() function

digg del.icio.us TRACK TOP
By Eric Downing | Filed in Programming, Scripting | No comments yet.

I was writing a basic guessing game and when I tried to take user input I was
getting the following:

Code:

guess = input()
d

Error:

Traceback (most recent call last):
  File "", line 1, in 
  File "", line 1, in 
NameError: name 'd' is not defined

The problem is actually with the version of Python that I was using. If you
are using Python 2.x, you need to use the raw_input() function. And with 3.x
you can use the input() function.

Tags: ,

Python: if/else Statements

digg del.icio.us TRACK TOP
By Eric Downing | Filed in Programming, Python, Scripting | No comments yet.

There comes a time when you are writing a program and you need to branch based on input to a program.
This is the format of the if/else statement in Python.

if <some true/false statement> :
  <some statements that run if the if statement is true>
else:
  <some other statements that run if the if statement are false>  

There may be times when you have more than one value set to test against. In that case you can write a many if/else
statements but you can chain the if/else statements with an elif. So the chain becomes if/elif/else.

if x < 5:
  <some statements that run if the if statement is true>
elif x > 5 and x < 10:
  <some statements that run if the elif statement is true>
else:
  <if none of the if checks are true, run the statements in the else case.>

Tags: ,

Python: Allow for empty if else blocks

digg del.icio.us TRACK TOP
By Eric Downing | Filed in Programming, Python, Scripting | No comments yet.

I was toying with a prime number finder and was creating a set of if/else statements for a horribly failed attempt
and wanted to skip to the next number on any of the if statements that were true. I didn’t want to put an empty print
statement as that would disrupt the output I was expecting from the program. I found the pass statement.
Here is an example from my not very successful attempt at finding primes:

if inp > 2 and inp % 2 == 0:
  pass
elif inp > 3 and inp % 3 == 0:
  pass
elif inp > 7 and inp % 7 == 0:
  pass
elif inp > 9 and inp % 9 == 0:
  pass
else:
  print inp, " is a prime"

Yes, this does not accurately find the primes, but it would skip any number that is divisible by 2,3,5,7, or 9. And
anything that does not match this will be listed as a prime, this is incorrect and would be made to add new elif
statements as each prime was found.

Tags: ,

C: Check if string is a number

digg del.icio.us TRACK TOP
By Eric Downing | Filed in C/C++, Programming | No comments yet.

I was recently testing some basic input and wrote this code to test if the input was a number or not.

#include 

int main()
{
  char name[10];

  scanf("%s",&name);
  if (checkifNumber(name))
  {
     printf("Is a numbern"); 
  }
  else
  {
     printf("Invalid numbern");
  }
}

int checkifNumber(char *inp)
{
  int i=0;
  int isanumber = 1;

  while(inp[i] != '' && i < 10)
  {
    if (inp[i] >= '0' && inp[i] <= '9')
    {
    }
    else
    {
      isanumber =0;
    }
    i++;
  }
  return isanumber;
}

One thing that could be improved is to potentially use a global variable to define the length of the
input string as it is used in two different places in the program and could potentially lead to an
array overrun/underrun.

Tags: ,

Dos: Adding commands to the PATH

digg del.icio.us TRACK TOP
By Eric Downing | Filed in OS, Shell, Windows | No comments yet.

When you install a new piece of software that does not add itself to the Windows PATH variable, you may find your self
needing it to be run from a command prompt. You could type the full command path each time you run the executable, but
it may be easier to add the directory to the PATH variable so that it is always available.

To add it for the current command prompt:

set PATH=%PATH%;"C:Program FilesSometool"

This will add the variable to the current command prompt environment but will go away once you close the window and will not
be available to other prompts unless you type it in again.

To add it to the Windows Environment, you can use the My Computer->Properties menu to select the “Advanced System Settings”
in Windows 7 to then select the “Environment Variables…”. Now the choice you have is to add it to the System variables or
the User variables for.

If you choose the System varables you will be adding it to the system as a whole and any other user who logs in will have
the updated path. If you add it to the User variables, then it is only available to your user.

Whichever you choose, select the Path entry and click the “Edit…” button. This will pop up a dialog that will let
you add to the “Variable Value” entry. Now you will need to decide whether you want your new path at the beginning, end,
or somewhere in the middle. You might add it to the beginning if it is being used to override an existing command. You
may add to the end if there is no conflict with other installs. And finally, you may need to choose the middle if there
are some commands you need to override but others that need to be left alone.

Entries are separated by the semi-colon “;” character in DOS.

Tags: ,