【发布时间】:2021-06-04 00:22:11
【问题描述】:
我有一个脚本,它依赖于位于特定文件夹中的不同文件,这些文件对于无错误运行脚本很重要。为了定义路径位置,我决定使用相应的路径位置名称作为字符串创建许多变量:
file directory var file directory location % default entries which
% only work with my computer
fd_1 = '\C:\Testrun\pathfinder.xls\';
fd_2 = '\C:\Testrun\pathfilter.slx\';
fd_3 = '\C:\Testrun\splinegenerator.xls\';
fd_4 = '\C:\Testrun\loftcreator.xls\';
fd_5 = '\C:\Testrun\surface_to_volume.xls\';
fd_6 = '\C:\Testrun\stp_creator.xls\';
fd_7 = '\C:\Testrun\CAD_file.stp\';
fd_8 = '\C:\Testrun\CAD_support_1.atm\';
fd_9 = '\C:\Testrun\CAD_support_2.atm\';
fd_10 = '\C:\Testrun\CAD_support_3.atm\';
这让我可以在我的电脑上使用我的脚本。然而,这是一个非常静态的解决方案,仅适用于一台电脑。因此,我需要对以下动态例程进行编码:
0.) I created a while loop in order to rerun my script with the switch case/expression:
<<<here is the missing code for the file directory check>>>
%(I wanted to use the "strcmp" command to compare the strings with each other?)
<<<Here is my code with the specific while loop to rerun it>>>
1.) Before I enter this loop need to perform a quick check, if the files are correctly located.
2.) If the file directory cannot be assigned to the specific variables responsible for the file
directory name (e.g directory could not be found), a new file directory will be choosen by the
user
3.) The newly choosen file directory will be stored with the default file directory in a list
4.) The variable responsible for the file directory changes according to the list index which the
user choose from the list of stored file directory names
5.) The selection of the specific list index as well as the changes in the list will be permenantly
stored (The changes in the list should be saved and recalled again in the script upon rerunning
or exiting/reopening the script)
6.) The list index can be deleted if the user is unsatisfied with the file directory (e.g due the
file directory corruption)
是否可以编写这样的代码以及如何构建它?
【问题讨论】:
-
这里的问题是什么?这篇文章中有各种各样的问题,其中一些或多或少可以回答,但最后一个问题是“有可能吗”,答案是“是的,但我们不会为您编写这样的代码,因为 1)我们不写您的代码 2)您的问题陈述含糊不清”。您能否尝试缩小您遇到问题的具体范围?
-
是的。我再解释一下。正如我上面提到的,我有一组特定的变量,其中包含文件夹中文件当前位置上方的信息。我的问题是,如果我想在另一台计算机上运行脚本,我不想手动编辑每个变量。因此,我需要一个能够添加新文件目录、保存新条目或删除旧条目的存储系统。
-
因此我很难申请编写这样的代码,因为我不熟悉代码架构,因为我之前没有遇到过这样的问题
-
我还不是很清楚。你想要创建这些文件的代码吗?或文件夹?如果您在另一台计算机上运行,文件不存在,那么您将如何创建它们?如果我们不知道文件里面有什么,我们如何帮助创建它们?
-
我想我的问题是:我似乎明白,当您在另一台计算机上运行此代码时,您想要在变量中填充这些路径名。但是如果你在不同的计算机上运行它,并且文件在不同的路径中,你怎么知道呢?您无法测试计算机的所有现有路径(这将花费太长时间),那么您如何知道文件在哪里?如果你能回答这个问题,那么我们可以找到一种方法让代码知道:)