Jump to content

Moving Files / Creatiung Directories


This topic is 5589 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I can easily get a file listing from a directory, but then I would like to move all of those files to other directories. I may also need to create the new directories these files will be moved to.

I was surprised that these two functions (fileMove and directoryCreate) are not already a part of ScriptMaster.

So I thought I would take a crack at creating these myself. Looking at the Groovy Reference site, in the File category, I don't see these methods.

Am I missing something simple?

Thanks.

Link to comment
Share on other sites

Hi Karstyn - you'll love learning Groovy/Java! Take a look at the class documentation for java.io.File:

http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html

in particular, you'll need to use the rename() method and the mkdir() or mkdirs() methods. If you get stuck, post your code and I'm sure somebody will be happy to help.

Link to comment
Share on other sites

Great - Thanks!

I was able to create a directoryCreate function easy enough. I am having problems with fileMove though.

This is what I'm starting with:

new File(origPath).renameTo(newPath)

where both parameters are fully qualified paths ending with the file name.

One question I have with paths - it seems that they always take forward slashes, correct? Regardless of platform?

Link to comment
Share on other sites

Seems to be a problem with my use of .renameTo() - I'm getting this error:

groovy.lang.MissingMethodException: No signature of method: java.lang.String.renameTo() is applicable for argument types: (java.lang.String) values: {"C:Documents and SettingskmccoyDesktopimagesMovedA0166433.jpg"}

Link to comment
Share on other sites

This topic is 5589 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.