0

So here are the questions:

  1. I have a folder, let's say C:\myFolder, and in this directory, I have many subfolders, and in each of this subfolders, I have exactly one folder, that contains pdf files, so my file structure looks something like this: C:\myFolder\someFolderInMyFolder\theOnlyFolderInThisFolder\*.pdf, now I want to move all these pdfs one level up, such that it will be like this: C:\myFolder\someFolderInMyFolder\*.pdf. Are there any command line commands, or scripts (that can be executed by Cygwin) that will help me with this?

    What could complicate the situation is that, I have manually move some files one level up by myself, so it will help if there is a check condition.

  2. I have some .zip files that the name are generated by computers, in the format of mm/dd/yy/fileIndex.zip, and the fileIndex is like No.001, for example. When I upload the extracted folders to Dropbox, and view the files on my iPad, it looks weird because the full folder name can not be displayed completely, so I want to rename each folder to someIndex, in the above example, from No.001 to 001, so same question here: any command or shell scripts?

4

1 回答 1

1

您可以使用@Endoro建议的稍微修改的版本将所有 PDF 上移一级:

@echo off

for /r "C:\myFolder" %%f in (*.pdf) do move "%%~ff" "%%~dpi.."

但是,脚本没有通用的方法来区分您已经移动的文件和尚未移动的文件。最好取消手动移动。否则,您将不得不找到一些显着特征或根据名称列表检查每个名称,例如像这样

您可以像这样重命名文件:

@echo off

setlocal EnableDelayedExpansion

for /r "C:\myFolder" %%f in (No.*.zip) do (
  set name=%%~nxf
  set name=!name:No.=!
  ren "%%~ff" "!name!"
)

endlocal

FTR,我不知何故怀疑您是否真的有名称像mm/dd/yy/fileIndex.zip. 正斜杠不是 Windows 中文件名的有效字符。

于 2013-04-13T16:46:33.823 回答