如何自动复制文件的路径太深的问题在Windows? [英] How do you automate copying file with path too deep issues in Windows?

查看:271
本文介绍了如何自动复制文件的路径太深的问题在Windows?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要能够选择性地复制文件列表并保留其目录结构。问题是,有相当多的文件,他们的路径超过256个字符。这个问题通常是如何处理的?

I want to be able to selectively copy a list of files and preserve their directory structure. The problem is that there are quite a few files that their path exceeds 256 character. How is this problem usually handled?

编辑:
我应该清楚,我只想选择性地复制文件,而不是文件夹。我不认为robocopy可以有效地用于复制单个文件和它的文件夹结构有效。

I should make it clear that I only want to selectively copy files, not folders. I don't think robocopy can be efficiently used to copy an individual file and it's folder structure effectively.

推荐答案

我写了一个VBscript它检查路径长度并在达到某个阈值时调用 subst 。这些调用堆叠在一起,因此在递归中间存在这种布局:

I wrote a VBscript that checks path length and calls subst, as soon as a certain threshold is reached. These calls are stacked on each other so that in the middle of a recursion, this layout exists:

C:\a\very\long\path
subst K: "C:\a\very\long\path"

K:\another\very\long\path
subst L: "K:\another\very\long\path"

L:\yet\another\very\long\path
subst M: "L:\yet\another\very\long\path"

xcopy M:\*.* "D:\target"

这样,对于subst的每个级别,生成一个更短的路径。

This way with each level of subst, a shorter path is generated. It also means, that you must copy your folders sequentially, to be able check for long paths before you issue the copy command.

复制文件夹中的所有文件后,您必须按顺序复制文件夹,以便在发出复制命令之前检查长路径。递归确实跳回一级( subst / d ),释放一个驱动器号。

Once all files in a folder are copied, the recursion does jump back one level (subst /d), freeing up one drive letter.

5个驱动器盘符,当其他路径到达时,我已经能够复制的路径长度在MAX_PATH限制以上的路径。

Using 4-5 drive letters, that subst each other when the path gets to deep I had been able to copy paths that had lengths waaaaay over the MAX_PATH limit.

EDIT

这描述了使用subst执行此操作的一般过程。你如何做到取决于你的需要,我总是使用这个小的技巧在最小,解决这个单一问题的方式。

This describes the general procedure of doing it with subst. How you do it depends on your needs, I always used that little subst trick in a minimal, "solves this single problem" way.

例如,复制到同等深度的目标路径意味着您需要另一堆替换的驱动器号。

For example, copying to an equally deep target path means you need another stack of subst'ed drive letters.

在一个深层嵌套的目录结构中解压所有.zip文件可能只需要堆栈,但您需要缩短阈值以解决文件夹。 zip等。

Unpacking all .zip files within a single, deeply nested directory structure may require only on stack, but you need to shorten the threshold a bit to account for folders in the .zip, etc.

这篇关于如何自动复制文件的路径太深的问题在Windows?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆