我想将两个文件从一个存储库移动到另一个存储库.这些文件最初添加为:
/src/init/Price.cs
/tests/init/PriceTests.cs
这两个文件后来被重命名为:
/src/init/PriceValue.cs
/tests/init/PriceValueTests.cs
然后转到:
/src/moved/PriceValue.cs
/tests/moved/PriceValueTests.cs
我试图通过这种描述为这些文件创建一组补丁,但我不确定如何传递文件存在的六种不同路径.
我设法找到影响PriceValue.cs
(跨重命名和移动)的所有提交ID ,但将这些ID传递给Git失败,并显示以下错误消息:
$ git format-patch -o /tmp/pricevaluepatches $(git log --all dfeeb 6966b 9f882 …)
-bash: /usr/local/bin/git: Argument list too long
Run Code Online (Sandbox Code Playgroud)
那么,我如何为此创建一组补丁,它只包含对所提到文件的更改,但是在一个重命名和每个文件的一次移动中包含它?
首先,这些是我的意图:
点1-3完美地工作.当我尝试移动数据库时,问题就开始了.我得到一个错误说明:
'The process cannot access the file because it is being used by another process.'
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
首先,我创建一个上下文.我必须在几种方法中使用它,我不想在每次需要时创建它.所以我将它存储为成员.
_sqliteContext = new SqlLiteContext(sqliteContextName);
Run Code Online (Sandbox Code Playgroud)
然后我想访问一个名为的表sync
并获取其最新条目.
var sync = _sqliteContext.Syncs.OrderByDescending(s => s.Date);
_lastSync = sync.Any() ? sync.First().Date : new DateTime(0);
Run Code Online (Sandbox Code Playgroud)
而已.然后我关闭上下文.
_sqliteContext.Dispose();
Run Code Online (Sandbox Code Playgroud)
并尝试移动文件.
File.Move(sqliteUploadLocation, sqliteDownloadLocation);
Run Code Online (Sandbox Code Playgroud)
这是我得到例外的地方.
当我用插入替换选择时,如下所示:
var sync = new Sync { Id = Guid.NewGuid().ToString(), Date = DateTime.Now };
_sqliteContext.Syncs.Add(sync);
_sqliteContext.SaveChanges();
Run Code Online (Sandbox Code Playgroud)
这有效,我可以移动数据库.任何想法为什么我的选择不释放锁定?
更新
// Start synchronisation.
new SyncManager(mssqlString, sqliteUploadLocation).Start();
// Move file from upload to download …
Run Code Online (Sandbox Code Playgroud) 我想将文件从复杂的目录结构移动到一个地方。例如,我有这个深层次的层次结构:
foo/
foo2/
1.jpg
2.jpg
...
Run Code Online (Sandbox Code Playgroud)
我希望它是:
1.jpg
2.jpg
...
Run Code Online (Sandbox Code Playgroud)
我目前的解决方案:
def move(destination):
for_removal = os.path.join(destination, '\\')
is_in_parent = lambda x: x.find(for_removal) > -1
with directory(destination):
files_to_move = filter(is_in_parent,
glob_recursive(path='.'))
for file in files_to_move:
shutil.move(file, destination)
Run Code Online (Sandbox Code Playgroud)
定义:directory
和glob_recursive
。请注意,我的代码仅将文件移动到它们的公共父目录,而不是任意目标。
如何简洁优雅地将所有文件从复杂的层次结构移动到一个地方?
我有一个同步软件,它从“传入”文件夹加载 CSV 文件,处理它们,然后将它们移动到“存档”文件夹。
今天,我看到这个同步软件出现以下错误:
[23/06/2014 00:06:04 AM]:无法从
D:\IBI_ORDER_IMPORTER_FTP_SERVER\Template3\Fifty & Dean\Incoming\5A040K___d6f1ca45937b4ceb98d29d0db4601bf4.csv 到
D:\IBI_ORDER_IMPORTER_FTP_SERVER\Template3\Fifty & Dean\Archive\5A040K___d6f1ca45937b4ceb98d29d0db4601bf4.csv -找不到路径的一部分。
这是从同步软件中提取的片段,文件在其中被处理和移动:
public static void ProcessSingleUserFile(Int32 TemplateId, String ImportedBy, String FilePath)
{
// Always Rename File To Avoid Conflict
string FileName = Path.GetFileNameWithoutExtension(FilePath);
String NewFilePath = FilePath.Replace(FileName, Utils.RandomString() + "___" + FileName);
File.Move(FilePath, NewFilePath);
FilePath = NewFilePath;
// Log
SyncUtils.ConsoleLog(String.Format("Processing [ {0} as {1} ] By [ {2} ] On Template [ #{3} ]",
FileName + ".csv",
Path.GetFileName(FilePath),
ImportedBy,
TemplateId));
// Init
List<OrderDraft> myOrderDrafts …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用移动文件SetFileInformationByHandle
.Niall Douglas在他的CppCon2015谈话"赛车文件系统"中提出了这种技术,作为原子地移动/重命名文件的一种方式.但是,我很难提供正确的论据; 它总是失败并GetLastError
返回ERROR_INVALID_PARAMETER
.
我使用Unicode字符集通过以下设置尝试了这个:
但行为是一样的.我确保可以访问测试文件夹和测试文件.
#include <sdkddkver.h>
#include <windows.h>
#include <cstring>
#include <iostream>
#include <memory>
int main()
{
auto const& filepath = L"C:\\remove_tests\\file.txt";
auto const& destpath = L"C:\\remove_tests\\other.txt";
// unclear if that's the "root directory"
auto const& rootdir = L"C:\\remove_tests";
// handles will be leaked but that should be irrelevant here
auto const f_handle = CreateFile(filepath,
GENERIC_READ | GENERIC_WRITE | DELETE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if …
Run Code Online (Sandbox Code Playgroud) 我将 Android Studio 设置中的项目默认位置从 更改/Documents/Android Studio projects
为/Documents/AndroidProjects
。然后我在文件资源管理器中将现有项目从前者移动到后者。然后我打开 Android Studio 并导入该项目。现在构建时出现此错误:
Build file 'C:\Users\Sourav Kannantha B\Documents\AndroidProjects\Skara\app\build.gradle' line: 1
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.internal.application']
> Failed to get default debug keystore location.
Run Code Online (Sandbox Code Playgroud)
我检查了所有的 gradle 文件,没有提到任何与路径相关的内容。所以我不知道是什么导致了这个错误。请帮我。
整个错误日志:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\Sourav Kannantha B\Documents\AndroidProjects\Skara\app\build.gradle' line: 1
* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.internal.application']
> Failed …
Run Code Online (Sandbox Code Playgroud) android file-move android-studio build.gradle android-gradle-plugin
标题解释了我所追求的。请注意,子目录不会包含任何目录,仅 包含文件(*.JPG)。本质上,只是将文件树中的所有内容向上移动一级。
例如,从 ~/someDir/folder1/*
, ~/someDir/folder2/*
, ... , ~/someDir/folderN/*
。我希望将子目录的所有内容都带到~/someDir/
.
我编写一个程序,它应该读出mp3文件的id3标签,创建一个名为艺术家的目录,然后我想将mp3文件移动到特定的艺术家目录.
当我试图移动Mp3文件时,它不会将其移动到我创建的Musik目录的子文件夹(命名为艺术家).我只想移动Mp3文件,而不是重命名它们.
这是我的代码:
public void moveFiles(string path, string[] title, string[] artist,string [] songs)
{//loop through the title array
for(int i=0;i<title.Length;i++)
{// no artist no name
if (artist[i] == null)
{
i += 1;
}//check if sourceFile is existing
if (File.Exists(songs[i]))
{//check if destinationFile is existing
if (File.Exists((@"C:\Musik\" + artist[i] + songs[i])))
{//if delete
File.Delete((@"C:\Musik\" + artist[i] + songs[i]));
}
else
{ //move file from songs[i](sourcePath)to (destinationPath)
File.Move(songs[i],(@"C:\Musik\" + artist[i] + songs[i]));
MessageBox.Show("Das Lied " + title[i] + " wurde erfolgreich …
Run Code Online (Sandbox Code Playgroud) 我有一个名为“四月报告”的文件夹,其中包含一个月中每一天的文件夹。然后,每个文件夹都包含另一个包含PDF文件的文件夹:
四月报告 2018年1月4日 ?天报表 ?批准.pdf ?未经批准.pdf ? 2018年2月4日 ?天报表 ?批准.pdf ?未经批准.pdf ? ? 2018年4月30日 天报表 批准.pdf 未经批准.pdf
PDF每天都有相同的名称,因此我要做的第一件事是将它们上移一个级别,这样我就可以使用包含日期的文件夹名称来重命名每个文件,以便包含日期。我尝试过的脚本是这样的(在“ April Reports”中设置了路径):
$files = Get-ChildItem *\*\*
Get-ChildItem *\*\* | % {
Move-Item $_.FullName (($_.Parent).Parent).FullName
}
$files | Remove-Item -Recurse
Run Code Online (Sandbox Code Playgroud)
删除多余文件夹“ dayreports”的步骤有效,但文件尚未移动。
我遇到了这个问题,其中 sftpChannel.rename 失败,错误不是很有帮助,我想不出原因。目标中不存在文件。权限很好,因为 mv 命令有效。我将列出文件和文件夹的权限。有人有任何想法吗?我不必使用该目录,但不知道为什么会失败令人沮丧。
这是一段测试代码。RemoteFile 只是 sftpChannel 的包装器,因此我可以检查文件/目录是否存在并在必要时删除文件或创建目录:
String file = "/u01/apps/tpms/applstg2/ken_test/TestFile";
String destDir = "/usr/local/jboss/server/applstg2/backup/"; // Caused by: 4: Failure
//String destDir = "/u01/apps/tpms/applstg2/ken_test/backup/"; // Success
RemoteFile remoteFile = new RemoteFile(file, ssh.openSftpChannel());
remoteFile.rename(destDir + "/TestFile");
Run Code Online (Sandbox Code Playgroud)
这是失败的行:
sftpChannel.rename(file, newName);
Run Code Online (Sandbox Code Playgroud)
这是跟踪(我删除了所有 JUnit 和 sun.reflect 跟踪):
Error renaming file /u01/apps/tpms/applstg2/ken_test/TestFile to /usr/local/jboss/server/applstg2/backup//TestFile
at com.framework.remote.RemoteFile.rename(RemoteFile.java:82)
at com.framework.remote.RemoteFileTest.renameFile(RemoteFileTest.java:56)
Caused by: 4: Failure
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2846)
at com.jcraft.jsch.ChannelSftp.rename(ChannelSftp.java:1923)
at com.framework.remote.RemoteFile.rename(RemoteFile.java:79)
Run Code Online (Sandbox Code Playgroud)
权限:
drwxrwxr-x 2 applstg2 applstg2 4096 May 2 22:09 ken_test
-rw-rw-r-- 1 applstg2 applstg2 61595086 …
Run Code Online (Sandbox Code Playgroud)