Change folder name where the jmp file is storedHi All,
I am doing a bunch of automation from the user input.
What if C:\Files\A\B files\data.jmp directory exists and currently I am getting Get default directory() function to get the entire path (C:\Files\A\B files\)as I store the script in the same folder.
I want to change folder B files to B_files. Is it possible?
Thanks.
Re: Change folder name where the jmp file is storedThese are amazing resources. Thank you Craige.
Thank you txnelson for helping me initially also.Re: Change folder name where the jmp file is storedRegular expressions are great for doing these sorts of tasks. There are lots of regex resources on the web and at least this and this I've posted in the community. In the example above, you could compare last == fixed to determine if you need to rename the directory.
I don't understand what you want to do with an IP address. You can't use JMP's rename functions to do anything to a URL. Rename only works on a disk that you have read/write access.
However, you can manipulate a URL (using regex or other JSL functions) before using it. For example, you could parse the URL for this page and rebuild it. The JSL could use regex, or words(URL,"/"), or other string functions.
URL="community.jmp.com/t5/Discussions/Change-folder-name-where-the-jmp-file-is-stored/m-p/45142";
w = words(URL,"/");
{"community.jmp.com", "t5", "Discussions",
"Change-folder-name-where-the-jmp-file-is-stored", "m-p", "45142"}
You could manipulate that list and rebuild the string
w[5] = "xyzzy";<BR />concatitems( w ,"/");
"community.jmp.com/t5/Discussions/Change-folder-name-where-the-jmp-file-is-stored/xyzzy/45142"
That's a 404-page not found URL, of course.
Re: Change folder name where the jmp file is storedI agree with your point Craige. Thats you, I am trying to figure out a way to ignore the space. I have the problem if I try to run the location with an ip address. If I just open it normally I don't have the problem.Re: Change folder name where the jmp file is storedmore thoughts: this may be not be a good idea, especially if you are renaming the current directory out from under the user. It makes it hard to save the script you just opened from the current directory. It is also going to fail the rename if your user makes "B Files" again when B_Files exists from a previous run. Be sure to test the return code from the rename function!
Re: Change folder name where the jmp file is storedHere's some regex to help with the name change
old = Get Default Directory(); // lucky it uses posix style forward slash...
Print( old ); // "/C:/Users/v1/Desktop/B Files/"
last = Regex( old, "([^/]+)/?$", "\1" ); // "B Files"
fixed = Regex( last, "[ @$]", "_", GLOBALREPLACE ); // "B_Files"
Rename Directory( old, fixed );
The first regex isolates the final sub directory. The second regex changes space, @ and $ to underscore. The first regex would need some ugly escaping if the path used back slashes. The first regex says "find a run of one or more characters that are not /, followed by an optional /, followed by the end of string." The parens form the backref \1 for the result. The second regex uses a character class in [ ] in case you have more than one special character to remove,
Re: Change folder name where the jmp file is storedThe Rename File() function allows you to change the file name. It will honor blanks withing the names, as will an Open() function. What am I missing?
Re: Change folder name where the jmp file is storedThank you txnelson for the suggestion. I went back and checked. Looks like I can't change the filename. Is there a way to ignore the space in calling or opening the file from the directory?Re: Change folder name where the jmp file is storedHere is the example taken directly from the Scripting Index for
Help==>Scripting Index==>Functions==>Rename Directory
Names Default To Here( 1 );
Delete Directory( "$TEMP/subD" );
Delete Directory( "$TEMP/Loss Function Templates" );
rc0 = Copy Directory(
"$SAMPLE_DATA/Loss Function Templates",
"$TEMP"
);
rc1 =
Rename Directory(
"$TEMP/Loss Function Templates",
"subD" /* NO PATH */
);
rc2 =
Directory Exists( "$TEMP/Loss Function Templates" );
rc3 = Directory Exists( "$TEMP/subD" );
rc4 = Delete Directory( "$TEMP/subD" );
rc5 = Directory Exists( "$TEMP/subD" );
Char( rc0 ) || " " || Char( rc1 ) || " " ||
Char( rc2 ) || " " || Char( rc3 ) || " " ||
Char( rc4 ) || " " || Char( rc5 );/* 1 1 0 1 1 0 */