标签: directory

无法使用C#删除目录和文件

我创建了安装程序,需要删除一些文件和文件夹(如果它们已经存在)并替换为新的。

当用户单击安装时,安装程​​序会提示输入 UAC。选择“是”后,安装程序将调用删除现有文件和文件夹的方法。但它无法删除文件和文件夹。我使用的代码是 DI.Delete(path)。它给出了这个错误

Access to the path 'CodeCreate.aspx' is denied.
   at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive)
   at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive)
   at System.IO.DirectoryInfo.Delete(Boolean recursive)
   at CustomizationCA.CustomActions.DeleteExistingFilesAndFolder(Session session)
Run Code Online (Sandbox Code Playgroud)

如果我以管理员身份运行命令提示符,然后使用“msiexec /i Setup.msi”命令,它会删除这些文件和文件夹。

当使用 Directory.Delete(path,true); 时 我将此视为例外

Exception thrown by custom action:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Security.SecurityException: The source was not found, but some or all event logs could not be searched.  Inaccessible logs: Security.
   at System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean …
Run Code Online (Sandbox Code Playgroud)

c# directory installation wix wix3.5

0
推荐指数
1
解决办法
2902
查看次数

Perl:如何全局访问所有且仅子目录?

我正在尝试编写一个 Perl 脚本来执行预排序目录遍历。我需要它来获取给定目录的所有子目录,包括隐藏的子目录。不幸的是,当我尝试以这种方式进行通配时:

<$dir/* $dir/.*>

... 原因 ”。” 和“..”也会被返回,这会扰乱我的函数,因为它会导致无限循环。如何获取$dir 的子文件夹(常规和隐藏),而不获取当前或上层目录?

例如,如果我的文件夹是“dir”并且它包含以下子目录:

你好
.hiddendir
“名称中带有空格的目录”
“名称中带有空格的.hidden目录”
dir2

...我想得到一个只有这些而不是“.”的数组。或者 ”..”。

我不在乎文件是否也出现,因为我稍后使用“if (-d $dir)”。有没有办法可以测试通配数组的元素是否等于当前目录或父目录,以便我可以排除它们?

谢谢

directory perl hidden glob traversal

0
推荐指数
1
解决办法
4120
查看次数

Directory.Exists() 无法识别不存在的文件夹(反斜杠错误)

我用来Directory.Exists()检查文件夹是否存在,但遇到该方法失败。我的命令是:

if (Directory.Exists(myFolder) == false) 
{ 
    MessageBox.Show(myFolder, "Invalid Log Folder path", MessageBoxButtons.OK, MessageBoxIcon.Hand); 
}

if (Directory.Exists(myFolder) == true) 
{ 
     MessageBox.Show(myFolder, "Valid Folder path"); 
}
Run Code Online (Sandbox Code Playgroud)

当 myFolder 为 时,C:\Documents and Settings\UserID\My Documents它返回TRUE

当 myFolder 是时C:\Documents and Settings\xxx\My Documents,它返回FALSE(假设xxx不存在)。

但是,当 myFolder 为 时,C:\\Documents and Settings\UserID\My Documents它也会返回TRUE.

旁边的双反斜杠C:必定使测试无效。然而,Directory.Exists()却没有认识到这一点。

使用更多\它仍然遇到同样的问题。

我只是无法理解这种失败是如何发生的。我正在使用 VS2008 和 .NET 3.5。

c# directory exists

0
推荐指数
1
解决办法
991
查看次数

两个目录之间的差异

下面是问题:假设在 DirA 中我有这些文件:

file1
file2
file3
file4
Run Code Online (Sandbox Code Playgroud)

在 DirB 中我有以下文件:

file1
file2
file3
Run Code Online (Sandbox Code Playgroud)

现在,如果我必须制作一个脚本来告诉我两个目录之间的差异(在本例中,dirB 中缺少 file4),并且还将文件复制到 DirB 中,那么命令是什么?

unix directory bash diff traversal

0
推荐指数
1
解决办法
477
查看次数

在 Python 中打开 Zip 文件中的文件夹

是否可以在不解压缩文件的情况下打开 zip 文件中的文件夹并查看其内容的名称?这就是我到目前为止所拥有的;

    zipped_files = zip.namelist()
    print zipped_files
    for folder in zipped_files:
        for files in folder:   #I'm not sure if this works
Run Code Online (Sandbox Code Playgroud)

有谁知道如何做到这一点?或者我必须提取内容?

python directory zip python-2.7

0
推荐指数
1
解决办法
5748
查看次数

C++,下载目录中的文件

所以我有这个简单的代码来从打开浏览器的网址下载文件

#include <iostream>
#include<Windows.h>
#include<string>

using namespace std;

int main()
{
    string dwnld_URL = "http://www.url.com/downloadpage";
    ShellExecuteA(NULL, "open", dwnld_URL.c_str(), NULL, NULL, SW_SHOWNORMAL);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但我希望文件位于当前目录中,而不是默认下载文件夹中。我有什么办法可以做到这一点吗?

c++ windows directory download

0
推荐指数
1
解决办法
3万
查看次数

创建 100 多个文件夹并按顺序命名

我尝试使用 os.makedirs() 工具创建 143 个文件夹,但遇到了一些麻烦。我一次只能生成一个文件夹,并且我想一次生成所有文件夹。我希望将文件夹命名为 IMG_0016 到 IMG_00160。

我想尝试使用带有计数器的 for 循环,其中每个循环都会将新数字添加到文件夹标题的末尾,但我无法让它工作。

import os

for folders in range(0, 143):
    count = 0016

    os.makedirs("C:\\Users\joshuarb\Desktop\Organized_Images\IMG"+count)

    count = count+1
Run Code Online (Sandbox Code Playgroud)

python directory

0
推荐指数
1
解决办法
2014
查看次数

将文件从根目录的子目录上移

我有以下文件夹层次结构:

----Folder
------Subfolders
-----------Sub-sub-folder
--------------Files
Run Code Online (Sandbox Code Playgroud)

所以我有多个子文件夹,并且在每个子文件夹中我都有一个包含多个文件的子子文件夹,我想从子子文件夹向上移动到子文件夹

最简单、最肮脏的方法是:只需将文件从子子文件夹复制到子文件夹,然后删除子子文件夹。但如果你知道更好的 pythonic 方法,请告诉我

python directory file

0
推荐指数
1
解决办法
1814
查看次数

为什么?!cp:使用--parents,目标必须是目录

我有一个命令(有效,但脚本运行时所有内容都是从终端输出复制粘贴的):

cp --parents mcare.properties /mnt/hgfs/Shared-workspace/Release/CRMT-mcare/msite-binaries-UAT/mcare/WEB-INF/classes
Run Code Online (Sandbox Code Playgroud)

该命令由带有变量而不是文件名或目录的脚本执行,它看起来像这样(并且这个不起作用):

cp --parents $source $destination
Run Code Online (Sandbox Code Playgroud)

记录以查看每个变量中的内容:

source=mcare.properties
pwd:
/mnt/hgfs/Shared-workspace/Workspaces-CVS/Release-CRMT-mcare/mCare/config/UAT/home/wlp/mcare/WEB-INF/classes
total 16
-rwxrwxrwx. 1 root root  6724 Feb 29 19:50 activareCont.properties
drwxrwxrwx. 1 root root     0 Feb 29 20:10 CVS
-rwxrwxrwx. 1 root root  2333 Aug 25 17:55 externalpartner.properties
-rwxrwxrwx. 1 root root  1764 May 26 10:36 login.properties
-rwxrwxrwx. 1 root root 10068 Aug 25 17:55 mcare.properties
-rwxrwxrwx. 1 root root  8551 May 27 16:04 msite.properties
config/UAT/home/wlp/mcare/WEB-INF/classes/mcare.properties
UAT/home/wlp/mcare/WEB-INF/classes/mcare.properties
medium=UAT
/mnt/hgfs/Shared-workspace/Release/CRMT-mcare/msite-binaries-UAT/mcare/WEB-INF/classes
cp: with --parents, the destination must …
Run Code Online (Sandbox Code Playgroud)

directory bash parent cp

0
推荐指数
1
解决办法
9006
查看次数

如何在Windows操作系统中的文件夹下的文件中搜索文本

在我的Windows机器中,我有一个文件夹,其中包含多个文件夹和多个文件,每个文件夹下都有不同类型的文件示例.txt、.properties、.xml、.sh、.bat 等...

现在我想识别文件夹内的文件中是否存在特定文本。

例如:我想识别包含该单词的所有文件

“au.com.galaxy”

有没有快捷方式可以做到这一点,而无需打开和搜索每个文件?

windows directory search text file

0
推荐指数
1
解决办法
3729
查看次数

标签 统计

directory ×10

python ×3

bash ×2

c# ×2

file ×2

traversal ×2

windows ×2

c++ ×1

cp ×1

diff ×1

download ×1

exists ×1

glob ×1

hidden ×1

installation ×1

parent ×1

perl ×1

python-2.7 ×1

search ×1

text ×1

unix ×1

wix ×1

wix3.5 ×1

zip ×1