1.

Solve : Rename and Move PDF Files to Folder?

Answer»

Hi,
I'm very new to Batch Programming and can't still try to create my own for the script I needed.
Say I have 10 or more pdf files in a folder --- c:\Invoices which I would like to transfer those pdf files to c:\Invoices\Moved Files
But before moving, I would like to rename these pdf files into a series using the user input so it would be a script like:
Code: [Select]set /p NameSeries=What is your name series?
Say the series input by user is "JENNY-0000" , then the pdf file names would be JENNY-0001, JENNY-0002, JENNY-0003 and so on until all the files where renamed say there are 20 pdf files to rename, then it would be JENNY-0020 for the last item.
Then all these files will be moved as mentioned above.
Thanks!
Sorry I will not write it for you. But I have some questions.
Is this something that has to be done very often?
Would like to do this inside of the graphical interface instead commandment prompt?
Yes, this will be done very often and by a lot of users.
Not sure what you mean by graphical interface but if that includes installing apps, then it is forbidden in our company that is why I can only study batch file scripting.Somebody NEEDS to tell you or your boss that use of DOS commands in Windows 8 is not the path Microsoft recommends for administrative tasks.

Microsoft recommends any and administrators learn PowerShell, whether they program or not. Microsoft has forums another means to help administrators manage takes in a Windows based work group.

Now CH is indeed the right place  to get help with  batch file scripts. Somebody will come here shortly.

Bear in mind CH cannot take any RESPONSIBILITY for problems you encounter.

What I mean to stress is that batch programming over r the years has not improved in areas  of critical management of more complex working scenarios  found in today's windows work group environments.

Here is a reference of interest:
Break Your Batch Habit and Move to PowerShell
Quote

Starting in Windows 2000 (1999), Microsoft added to its scripting power by introducing the Windows Script Host (WSH) and two real, built-in, programming languages (VBScript and JScript--Microsoft’s version of JavaScript). WSH scripts rely on COM objects to interface with the operating system and applications. While WSH is extremely useful and powerful, it’s limited to COM objects that are installed on the computer and doesn’t provide a command-line interface.
The article goes on to explain how PowerShell is now the preference for command line scripts. Batch files can support PowerShell scripting.

Please understand my concern.  Hi Geek, it is new for me to hear Powershell. I'm reading it now and its good to know that there are no addtl apps needed to install but just saving it to Name.ps1 instead of .bat. Does this mean that my query above can be done using powershell? ThanksI still can't figure out how to write it in batch or in powershell but anyone who can help me with this please. Here's the scenario of the code:
Code: [Select]set $nameseries = What is your name series?
ForEach *.pdf {
$nameseries = $nameseries +1
rename $nameseries
move C:\Invoices c:\Invoices\Moved_Files
Thanks a lot in advance!
Quote from: austinandreikurt on August 20, 2016, 11:39:42 PM
Say the series input by user is "JENNY-0000" , then the pdf file names would be JENNY-0001, JENNY-0002, JENNY-0003 and so on until all the files where renamed say there are 20 pdf files to rename, then it would be JENNY-0020 for the last item.

Your task isn't very clear at this point.
You've said that the user types "JENNY-0000" but haven't said why they are typing the "0000" part.

Batch file commands do precise things, and if the task isn't WELL laid out then the code you get may not work.Hi, the name series depends on the user but it will always state a 5 letter word, then a hypen "-" then four 0's that will represent the max of 9999 files to rename and move.but it is also ok to just ENUMERATE the 5letter word by the user's input and the script automatically put a 4 number series starting from 0001 to 9999.

Also, the reason why it needs to be 0001 instead of just 1 is to be able to sort the items when moved because JENNY-1 will have JENNY-10 as the next one instead of JENNY-2. To avoid it, we need to have it like JENNY-0001, JENNY-0002, JENNY-0003 and so on. Quote from: austinandreikurt on August 21, 2016, 05:54:45 AM
Hi, the name series depends on the user but it will always state a 5 letter word, then a hypen "-" then four 0's that will represent the max of 9999 files to rename and move.but it is also ok to just enumerate the 5letter word by the user's input and the script automatically put a 4 number series starting from 0001 to 9999.
What do you expect to happen when Jenny already has backup files Jenny-0001.pdf to Jenny-0020.pdf and then Jenny has some more files to save?Jenny files should be 867-5309...Hi foxidrive.the batch will just overwrite them as it is regularly cleaned-up by the user so there should be no duplicates.Test this script and let me know how it goes.

Code: [Select]echo off
setlocal enabledelayedexpansion
   set /p "name=Enter your 5 character name: "
   set c=10000
   set "folder=Moved_Files"
   md "%folder%" 2>nul
      for %%a in (*.pdf) do if exist "%folder%\" (
          set /a c+=1
          move "%%a" "%folder%\!name!-!c:~-4!%%~xa"
     )
pause


I think Jenny works at a different phone number down here.
Quote from: patio on August 21, 2016, 09:18:28 AM
Jenny files should be 867-5309...
Wow. exactly what I need. thanks a lot foxidrive!


Discussion

No Comment Found