Append just the filename to other files

Hi,

The title does not do justice for what I need done, this by the way may stump people.  I am a newbie (to powershell and this forum) so please be gentle.

I have a bunch of pdf portfolio's ( a pdf portfolio/collection) for those who do not know are a bunch of pdf files inside of one pdf file).

I use pdftk to unpack the portfolio (and basically extract the files contained in that one pdf).

So for example lets say I have 3 pdf's:

doyle.pdf

gates.pdf

jobs.pdf

I run pdftk and the extraction looks somewhat like the following:

doyle.pdf

whale.pdf

Zebra.pdf

moth.pdf

gates.pdf

whale.pdf

cobra.pdf

moth.pdf

jobs.pdf

shark.pdf

horse.pdf

cat.pdf

zebra.pdf

I now have the original files together with the extracted/unpacked files.  As you can see some of the extracted files have the same file name as others that have been extracted.  I need a way to append the original filename with it's corresponding extracted file

for example;

doyle-whale.pdf

Doyle-zebra.pdf

doyle-moth.pdf

gates-whale.pdf

gates-cobra.pdf

.

.

.

jobs-zebra.pdf

Any help would be greatly appreciated.  I don't expect anyone to write the code for me but to steer me in the right direction.

Thanks all!

August 26th, 2015 8:27pm

Hi,

The title does not do justice for what I need done, this by the way may stump people.  I am a newbie (to powershell and this forum) so please be gentle.

I have a bunch of pdf portfolio's ( a pdf portfolio/collection) for those who do not know are a bunch of pdf files inside of one pdf file).

I use pdftk to unpack the portfolio (and basically extract the files contained in that one pdf).

So for example lets say I have 3 pdf's:

doyle.pdf

gates.pdf

jobs.pdf

I run pdftk and the extraction looks somewhat like the following:

doyle.pdf

whale.pdf

Zebra.pdf

moth.pdf

gates.pdf

whale.pdf

cobra.pdf

moth.pdf

jobs.pdf

shark.pdf

horse.pdf

cat.pdf

zebra.pdf

I now have the original files together with the extracted/unpacked files.  As you can see some of the extracted files have the same file name as others that have been extracted.  I need a way to append the original filename with it's corresponding extracted file

for example;

doyle-whale.pdf

Doyle-zebra.pdf

doyle-moth.pdf

gates-whale.pdf

gates-cobra.pdf

.

.

.

jobs-zebra.pdf

Any help would be greatly appreciated.  I don't expect anyone to write the code for me but to steer me in the right direction.

Thanks all!

Free Windows Admin Tool Kit Click here and download it now
August 26th, 2015 8:27pm

Hi,

The title does not do justice for what I need done, this by the way may stump people.  I am a newbie (to powershell and this forum) so please be gentle.

I have a bunch of pdf portfolio's ( a pdf portfolio/collection) for those who do not know are a bunch of pdf files inside of one pdf file).

I use pdftk to unpack the portfolio (and basically extract the files contained in that one pdf).

So for example lets say I have 3 pdf's:

doyle.pdf

gates.pdf

jobs.pdf

I run pdftk and the extraction looks somewhat like the following:

doyle.pdf

whale.pdf

Zebra.pdf

moth.pdf

gates.pdf

whale.pdf

cobra.pdf

moth.pdf

jobs.pdf

shark.pdf

horse.pdf

cat.pdf

zebra.pdf

I now have the original files together with the extracted/unpacked files.  As you can see some of the extracted files have the same file name as others that have been extracted.  I need a way to append the original filename with it's corresponding extracted file

for example;

doyle-whale.pdf

Doyle-zebra.pdf

doyle-moth.pdf

gates-whale.pdf

gates-cobra.pdf

.

.

.

jobs-zebra.pdf

Any help would be greatly appreciated.  I don't expect anyone to write the code for me but to steer me in the right direction.

Thanks all!

August 26th, 2015 8:27pm

To keep the files separate, you could create a temporary directory that matches the pdf file's name (without the extension), extract the contents to that directory, move each item back to the current directory with the new name, then remove the temporary directory. Example:

Free Windows Admin Tool Kit Click here and download it now
August 26th, 2015 8:42pm

Hi Bill,

Thanks for your prompt response.  

I will try to do this but I'm not sure if this is a viable solution. What I neglected to mention is the fact that this process will have to go through 1000's of pdf's.

Thanks again!

August 28th, 2015 8:50am

Hello All.

I have a bunch of files:

month.pdf

calendar

year.pdf

day.pdf

As you can see calendar does not have an extension.  It did, it was a pdf as well but I removed it.  I would like to append the calendar filename to month as well as to the other files so it should look something like this:

calendar-month.pdf

calendar-year.pdf

calendar-day.pdf

If there needs to be a calendar-calendar I would like that file to be deleted afterwards.

I don't expect the code to be written for me but just to be steered in the right direction.

Thanks !


Free Windows Admin Tool Kit Click here and download it now
August 28th, 2015 9:12am

"calendar" + $filename
August 28th, 2015 9:56am

If you're not familiar with how to use PowerShell, now is a good time to start learning.

What I posted above is merely a proof-of-concept that you will need to customize. It can be designed to run as a loop for multiple files.

Free Windows Admin Tool Kit Click here and download it now
August 28th, 2015 10:25am

Here's a method of getting filenames that have no extension:

$filename = Get-ChildItem .\ -File | 
    Where { !($_.Extension) } | 
        Select -ExpandProperty BaseName

August 28th, 2015 10:38am

Thanks Mike!
Free Windows Admin Tool Kit Click here and download it now
August 28th, 2015 10:50am

Hi Bill,

Thanks for your help - I tried your code and it works beautifully.  

I never had to use Powershell before but I can see it's power and usefulness.

All the best!


August 28th, 2015 10:50am

Thanks JRV, I'll try that.
Free Windows Admin Tool Kit Click here and download it now
August 28th, 2015 10:51am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics