Copy all formulas and paste them in cmd.Copy or import your target/new filenames from output.txt next to the old filenames.Use Data > Text to columns to split the filenames from the time stamps.Copy the lines with filenames and timestamps into an Excel sheet.This video is a step by step guide for some of this solution:Ĭreate a list of your current (old) file names: If you already have a list with file names (output.txt) consider using excel (or OpenOffice) and the command prompt cmd. So after all the script runs your "extractedFiles1" folder's gonna look something like this:ĭespite this being an older thread, I wanted to offer another "brute force" option.ĬodeNagi's reply works well in PowerShell, although it took me a bit to get working. Thus it follows this logic: Renaming file renameto1.txt to renametoA.txt The script actually renames the files in the "extractedFiles1" folder according to the names from the output.txt file. There are 6 text files inside the "extractedFiles1" folder which you can see in the image. Outputfile.txt file contains the names below: renametoA The script below takes a text file input which contains the name that should be used to rename each text file you have. Renaming file renameto6.txt to renametoF.txt ![]() ![]() Renaming file renameto5.txt to renametoE.txt Renaming file renameto4.txt to renametoD.txt Renaming file renameto3.txt to renametoC.txt Renaming file renameto2.txt to renametoB.txt Results: Renaming file renameto1.txt to renametoA.txt Rename-Item -Path $filestochange.FullName -NewName ($FileNames ".txt") Write-host "Renaming file $($filestochange.Name) to $($FileNames ".txt")" $FileNames = Get-Content "$BasePath\outputfile.txt" $filestochange = Get-ChildItem -Path "$BasePath\$FilesToChangeFolderName" $FilesToChangeFolderName = 'extractedFiles1' Not the most elegant looking solutions but hopefully this is what you are looking for? Do be mindful with the sorting of the filenames in your outputfile.txt and how the folders are listed when you get the childitem. ::Note that exclamation marks must not occur within the given string.Not entirely sure what's your setup or desired output is but give this a whirl bud. ::This function splits off the last `_`-separated item of a string. :GET_LAST_ITEM rtn_last rtn_without_last val_string Rem // Enable delayed expansion to be able to read the variables: ![]() Rem // Call sub-routine that removes the last `_`-separated part: Rem // Store current file name and extension: Setlocal EnableExtensions DisableDelayedExpansionįor /F "delims= eol=|" %%F in ('dir /B /A:-D "%_SOURCE%\%_MASK%"') do ( Note that this fails in case any of the files contains exclamation marks ! in their names. Here is a modified script that I posted in another answer, relying on a nice hack to remove the last portion of a string separated by a certain character – the underscore _ in this case. The last string assigned to %%b will be _laststring.ext, so the value assigned to newname will fit the processing requirement, so rename the file. Use a simple for to assign newname to the original filename with the _string removed (replaced by nothing) and add back the extension using %%~xa. WIth each name found, using delayed expansion, assign the name to filename and then replace each _ with Space_ Perform a directory scan of all filenames matching the mask. After you've verified that the commands are correct, change ECHO(REN to REN to actually rename the files. The required REN commands are merely ECHOed for testing purposes. You would need to change the setting of sourcedir to suit your circumstances. FOR %%b IN (!partsname!) DO SET "newname=!filename:%%b=!%%~xa"
0 Comments
Leave a Reply. |