用于读取和过滤 .cfm 文件的 ColdFusion 代码

发布于 2025-01-07 13:56:35 字数 216 浏览 0 评论 0原文

是否可以编写执行以下操作的 ColdFusion 代码?

  1. 读取 .cfm 文件
  2. 过滤 .cfm 文件中任何附加有“.cfm”的单词。
  3. 将步骤 2 中找到的文件名列表与目录中的文件进行比较,以查明该目录中是否存在 .cfm 文件之外的文件。

在步骤 2 中,我尝试在 href 中查找 .cfm 文件名。

谢谢

Is it possible to write a ColdFusion code that does the following?

  1. Read a .cfm file
  2. Filter the .cfm file for any word that has ".cfm" appended to it.
  3. Compare the list of file names found in Step 2 with files in a directory, to find out if there are any files in the directory that are not in the .cfm file.

In step 2 I am trying find .cfm file names in href.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葵雨 2025-01-14 13:56:35

我的测试目录设置有 reader.cfm 和 list.cfm。它能够在示例列表文件中找到 list.cfm 文件,并将 reader.cfm 文件记录为不存在。

可能有更好的方法从文件中获取 cfm 文件名列表。我不是正则表达式的专家,但我确实测试过它是否按预期工作。如果您的链接具有特殊字符(如 _ 或 -),它可能不起作用。不过,这应该会给你一些开始的东西。

<cffile action="read"
    file="#expandpath('list.cfm')#"
    variable="fileList">

    <cfset fileResult = rematchNoCase('([a-z]|[A-Z]|[0-9])+\.cfm', fileList)>

    <cfdirectory
        directory="#expandPath('.')#"
        action="list"
        filter="*.cfm"
        listInfo="name"
        recurse = "no"
        type="file"
        name="dirList">

    <cfset notInFile = ArrayNew(1)>

    <cfoutput>
        <cfloop query="dirList">
            <cfloop from="1" to="#arrayLen(fileResult)#" index="i">
                <cfif dirList.name eq fileResult[i]>
                    found one! #dirList.name#<br>
                    <cfbreak>
                </cfif>
                <cfif i eq #arrayLen(fileResult)#>
                    Item not found! #dirList.name#<br>
                    <cfset _r = ArrayAppend(notInFile, dirList.name)>
                </cfif>
            </cfloop>
        </cfloop>
    </cfoutput>

    <cfdump var="#notInFile#">

我使用的 list.cfm 文件的内容。

<a href="someRealLink.cfm">click me to fun</a>
something
other thing
a coldfusion.cfm thing
stuff
things
yar.cfm
blah
Something.cfm
0912.cfm
some123.cfm
cfm
list.cfm

第一个循环循环遍历我们的目录内容。第二个循环循环遍历我们正在查看的 cfm 文件内的数字数组条目。第一个 if 块查看当前数组位置内容并将其与外部循环名称值进行比较。第二个 if 查看当前数组位置值和可能的最大数组位置值。我们知道是否到达了当前位置 == 可能的最大位置 - 在内循环(文件数组)中找不到外循环元素(目录列表)。这是对第一个 if 块中的 执行的操作。当我们找到有效匹配时,此 将跳出第二个内部循环。这可以防止第二个 if 块在有效查找上执行。

希望这有帮助。如果您觉得答案已得到解答,请不要忘记接受答案XD

The directory of my test was setup with a reader.cfm and a list.cfm. It was able to find the list.cfm file in the example list file and logged the reader.cfm file as not being present.

Theres probably a better way to get a list of cfm filenames from a file. I'm no guru at regex, but I did test that it worked as desired. It probably won't work if your links have special chars like _ or -. This should give you something to start with though.

<cffile action="read"
    file="#expandpath('list.cfm')#"
    variable="fileList">

    <cfset fileResult = rematchNoCase('([a-z]|[A-Z]|[0-9])+\.cfm', fileList)>

    <cfdirectory
        directory="#expandPath('.')#"
        action="list"
        filter="*.cfm"
        listInfo="name"
        recurse = "no"
        type="file"
        name="dirList">

    <cfset notInFile = ArrayNew(1)>

    <cfoutput>
        <cfloop query="dirList">
            <cfloop from="1" to="#arrayLen(fileResult)#" index="i">
                <cfif dirList.name eq fileResult[i]>
                    found one! #dirList.name#<br>
                    <cfbreak>
                </cfif>
                <cfif i eq #arrayLen(fileResult)#>
                    Item not found! #dirList.name#<br>
                    <cfset _r = ArrayAppend(notInFile, dirList.name)>
                </cfif>
            </cfloop>
        </cfloop>
    </cfoutput>

    <cfdump var="#notInFile#">

Contents of list.cfm file I used.

<a href="someRealLink.cfm">click me to fun</a>
something
other thing
a coldfusion.cfm thing
stuff
things
yar.cfm
blah
Something.cfm
0912.cfm
some123.cfm
cfm
list.cfm

The first loop cycles through our directory contents. The 2nd loop cycles through the number array entries we have inside the cfm file we're looking at. The first if block looks at the current array location contents and compares it to the outer loops name value. The 2nd if looks at the current array location value and the max array location value possible. We know if we reached a current locaction == max location possible - the outer loop element (the directory list) wasn't found in the inner loop (the file array). This is do to the <cfbreak> in the first if block. This <cfbreak> will break out of the 2nd inner loop when we find a valid match. This prevents the 2nd if block from ever executing on a vaild find.

Hope this helps. Don't forget to accept an answer if you feel it's answered XD

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文