命令以255个字符截断所有文件名 [英] Command to truncate all filenames at 255 characters
本文介绍了命令以255个字符截断所有文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在bash shell中打开了一个NTFS目录.什么命令将递归地将目录中的所有文件名截断为ext3所需的255个字符的限制?
An NTFS directory is open in a bash shell. what command will recursively truncate all filenames in a directory to the 255 character limit required for ext3?
推荐答案
如果可以访问Windows shell,则可以使用:
If you have access to a Windows shell, you can use:
@echo off
setlocal EnableDelayedExpansion
REM loop over all files in the cwd
for /f %%a in ('dir /a-d /b') do (
REM store this filename in a variable so we can do substringing
set ThisFileName=%%a
REM now take a substring
set ThisShortFileName=!ThisFileName:~0,255!
REM finally, the rename:
echo ren %%a !ThisShortFileName!
)
:EOF
endlocal
(注意:我在重命名命令之前添加了一个回显,因此您可以在实际运行它之前直观地验证它是否可以工作.在我的机器上可以工作.)
(Note: I have added an echo before the rename command just so you can visually verify that it works before actually running it. Works on my box.)
我确定现在在* nix框上的人可以为bash编写类似的脚本,但是我陷入了Windows世界:)
I'm sure somebody who's on a *nix box right now could make a similar script for bash, but I'm stuck in Windows world :)
祝你好运!
这篇关于命令以255个字符截断所有文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文