大家好,
我是一个脚本傻瓜,需要一只手才能完成一项简单的任务。 我需要一个脚本,允许用户选择单个目录,在目录中查找CSV文件,并将文件追加/连接到单个JMP数据表中。 现在,每次用户运行脚本时,如果使用目录中的CSV文件重建这个“主数据表”就没问题了。
我做了一些研究,并从常驻超级用户天才txnelson中找到了应该完成任务的东西,但是当我运行它时,我收到一个错误,我不明白为什么。 剧本:
Names Default To Here( 1 );
// Setup an empty table to start to concatenate other tables to
dtbase = New Table( "Base Table" );
// Have the user select the starting folder
dirpath = Pick Directory( "Pick the Top Level Directory" );
// Get all of the files in all of the folders that are under the picked folder
TheFileList = Files In Directory( dirpath, "recursive" );
// Go through all of the files and read in append those that meet your
// requirement. You will need to amend the IF statement to meet your criteria
For( i = 1, i <= N Items( TheFileList ), i++,
If( Uppercase( Word( -1, TheFileList, "." ) ) == "CSV" & Is File( dirpath || TheFileList ) == 1,
dt = Open( dirpath || TheFileList );
dtbase = dtbase << concatenate( dt, append to first table( 1 ) );
Close( dt, nosave );
);
);当我运行脚本时,它会一直运行,直到我选择目录,然后没有任何反应。 我逐步完成了代码,这里是抛出错误的地方:
参数应该是访问或评估'Word',Bad Argument(TheFileList),Word / * ### * /( - 1,TheFileList,“。”)中的字符。
我不明白这个行话是什么意思。 代码似乎有道理。 为什么它不起作用?
谢谢,抱歉是个白痴。
很高兴你弄明白了,对不起,我可以解释一下。在吉姆尼尔森发布该代码后不久,JMP社区经历了一次重大转变。你遇到的问题是我现在仍在追赶的问题博客帖子:有时转换过程会从嵌入帖子的JSL中删除下标。(如果你在Jim的帖子中看得更远,你可以看到有人拍摄的照片,其中包含下标...这几个月真的是对的!)
@txnelson @Jeff_Perkinson
古代的帖子
通过做一些更多的研究来解决这个问题 - 我想需要在括号中加入一点“i”来循环遍历目录中的文件所选择的不同文件,这些文件被分配给TheFileList。 我甚至不知道从哪里开始 - 不知道人们可以循环通过这样的“项目” - 甚至不知道在700 +页面JSL指南中哪里可以找到这个功能。 脚本编写是不可能的。
If( Uppercase( Word( -1, TheFileList[i], "." ) ) == "CSV" & Is File( dirpath || TheFileList[i] ) == 1,
dt = Open( dirpath || TheFileList[i] );
dtbase = dtbase << concatenate( dt, append to first table( 1 ) );
Close( dt, nosave );
);
);