Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

CreateFolder Module - using variable in pathToCreate?

Featured Replies

  • Newbies

I want the folder to be created to be names as today's date in a Month-Day-Year format. So 8-9-2012. I added calendar code to it:

//Really simple version:

//return new File(path).mkdirs();

//Version with decent error reporting:

File dir = new File(pathToCreate);

Calendar cal = new GregorianCalendar();

// Get the components of the date

int year = cal.get(Calendar.YEAR);

int month = cal.get(Calendar.MONTH);

int day = cal.get(Calendar.DAY_OF_MONTH);

if( dir.exists() ) return false;

if( dir.mkdirs() ) { //Success!

return true;

} else { //Figure out why it failed

File realParent = dir;

while( realParent != null && ! realParent.exists() ) {

realParent = realParent.getParentFile();

}

if( realParent != null && !realParent.canWrite() ) {

throw new FileNotFoundException("Directory " + dir.getAbsolutePath() + " could not be created because the parent directory " + realParent.getAbsolutePath() + " is not writeable" );

} else {

throw new FileNotFoundException("Directory + " + dir.getAbsolutePath() + " could not be created because of an unknown error." );

}

}

but how do I get variables to work in the pathToCreate? I tried /Users/erickornmeyer/Desktop/DBPrice Updates/Pricing/Vendor Cost Updates/$month-$day-$year but it didn't do anything. Any help would be appreciated!

You are making the file object before the calendar stuff and then not doing anything with it

This might get you nearer




Calendar cal = new GregorianCalendar()



// Get the components of the date

int year = cal.get(Calendar.YEAR)

int month = cal.get(Calendar.MONTH)

int day = cal.get(Calendar.DAY_OF_MONTH



SEP = System.getProperty('file.separator')

pathToCreate = pathToCreate + SEP + month + '-' + day + '-' + year

// will give e.g. path/child/01-31-2012



File dir = new File(pathToCreate)



if( dir.exists() ) return false

if( dir.mkdirs() ) { //Success!

return true

} else { //Figure out why it failed

File realParent = dir

while( realParent != null && ! realParent.exists() ) {

realParent = realParent.getParentFile()

} //end while

if( realParent != null && !realParent.canWrite() ) {

throw new FileNotFoundException('Directory ' + dir.getAbsolutePath() + ' could not be created because the parent directory ' + realParent.getAbsolutePath() + ' is not writeable' )

} else {

throw new FileNotFoundException('Directory + ' + dir.getAbsolutePath() + ' could not be created because of an unknown error.' )

} //end if

} //end if





although you could do

end = new Date().format ('mm-dd-yyyy')

pathToCreate = pathToCreate + SEP + end

  • Author
  • Newbies

end = new Date().format ('mm-dd-yyyy')

pathToCreate = pathToCreate + SEP + end

Worked great except the output was 31-14-2012 for today. Not sure where it is getting that month value

Changed it to MM and it works now, thanks!

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.