0
I have a folder full of files of the format "10389-2001.pdf", so first a five digit number, a hypthen, and then a four-digit number. I want to rename all of the so that the file itself only is called "2001.pdf", but that it is moved into a new subfolder "10389". Since this subfolder does not exist yet, it would need to be created.
I am open to suggestions of how to do this on the Windows Command line, the Powershell, or Cygwin.
Have you tried anything? In PowerShell, I think that you only need to use
.Stubstring(0,"-")
of the file'sBaseName
and.Substring(1,"-")
of the file'sName
to get going:Move-Item -Path $original_file.FullName -Destination "$($(Split-Path -Parent -Path $original_file.FullName)\$($original_file.BaseName.Substring(0,"-"))\$($original_file.Name.Substring(1,"-"))"
– flolilo – 2017-08-31T14:45:29.2532Hi, and welcome to SuperUser. We are not a "please write me a script" kind of service. If you share your research, we'll help you point out where things are not working correctly. The solution can be done in any of the mentioned tools you want to use. For Batch, you will want to look into the command FOR. – LPChip – 2017-08-31T14:50:08.860
Hi, thanks for your responses. I am completely incompetent with PowerShell, so I have not tried anything there. I am familiar with the FOR command on the command line to create a loop, but I was struggling with the string manipulations there. – user1769925 – 2017-08-31T14:54:00.863