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?

Community
  • 1
  • 1
MathCs
  • 185
  • 1
  • 1
  • 10
  • Please don't ask about two very different problems in one post. You will likely get better quality answers with two questions posted separately. – Andriy M Apr 13 '13 at 17:04

1 Answers1

1

You can move all PDFs up one level with a slightly modified version of what @Endoro suggested:

@echo off

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

However, there is no generic way for the script to distinguish files you already moved from files that have yet to be moved. It might be best if you undid your manual moves. Otherwise you'll have to find some distinguishing feature or check each name against a list of names, e.g. like this.

You can rename files like this:

@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, I somehow doubt that you really have files with names like mm/dd/yy/fileIndex.zip. Forward slashes are not valid characters for file names in Windows.

Community
  • 1
  • 1
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328