Home / Microsoft / Microsoft DOS / Prefix file names
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] - (Bottom) Print
Author Topic: Prefix file names  (Read 397 times)
Mat51
Topic Starter
Rookie



Posts: 18

Experience: Beginner
OS: Unknown

« on: December 29, 2011, 11:50:56 AM »

Hi Guys,

I have a list in my subdirectory, which I have prefixed with dates.

@echo off
pushd C:\Reservoir Management\Petrolink Downloads\Block_17\Aug\13
::for /f "tokens=*" %%a in ('dir /b /a-d')
for %%a in (*) do rename "%%a" "20111213    %%a"
popd

I would l to do the following;
 trim the file names i.e removing the dates at the end
 if the file name contain a string such as DDR, then it should copy those files to a folder DDR
if the file name contain a string such as DGR, then it should copy those files to a folder DGR e.t.c

see example of one of the file names;
ACA-810_DDR62 7092011.pdf.

at the moment my code is doing this; adding prefix date
2011105   ACA-810_DDR62 7092011.pdf.

I want to remove the string date 7092011 and since it contains string DDR, then the file should be copied into DDR folder.

Many Thanks.......
IP logged
patio
Moderator
Genius



Thanked: 1069
Posts: 11,351

Experience: Beginner
OS: Windows 7


Maud' Dib

« Reply #1 on: December 29, 2011, 12:55:38 PM »

Are your problems and questions related to your job?

How much should the experts at Computer Hope charge for their answers?

Thats uncalled for...

How long have you been here ? ?
IP logged

   
"
All generalizations are false, including this one.  "
Raven19528
Hopeful



Thanked: 29
Posts: 284

Computer: Specs
Experience: Experienced
OS: Windows 7



« Reply #2 on: December 29, 2011, 01:09:17 PM »

From what I can tell, the dates at the end are not of standard length. This presents a little bit of an issue. Again, the coding will have to use some switches turned on and off to get things to work right.

A few things:

1. Are you wanting the date that is added to be a date you specify, or the date the program is ran?
2. Are you wanting to copy the files into the specified folders, or move them in there? (I.e. delete them from the source)
3. Please disregard the comment made by Candace. I too have posted work-related questions. I'm sure most people here have.
IP logged

"All things that are
Are with more spirit chased than enjoy'd" -Shakespeare
Squashman
Hopeful



Thanked: 25
Posts: 341

Experience: Experienced
OS: Other



« Reply #3 on: December 29, 2011, 01:31:39 PM »

From what I can tell, the dates at the end are not of standard length.
I would agree with that as it looks like his example is July 9 2011.  This means when you get to October the date length is going to be 1 character longer. This is why you should always use fixed length date format.  20120101 (January 1, 2012)

But if there is always only one space in the file name followed by the date then we could use the delims option to separate the file name.

IP logged
Raven19528
Hopeful



Thanked: 29
Posts: 284

Computer: Specs
Experience: Experienced
OS: Windows 7



« Reply #4 on: December 29, 2011, 02:19:08 PM »

But if there is always only one space in the file name followed by the date then we could use the delims option to separate the file name.

We could, but I think it would be easier to just take off 7 characters, then test for a 1 and remove if found.
IP logged

"All things that are
Are with more spirit chased than enjoy'd" -Shakespeare
Squashman
Hopeful



Thanked: 25
Posts: 341

Experience: Experienced
OS: Other



« Reply #5 on: December 29, 2011, 04:16:56 PM »

We could, but I think it would be easier to just take off 7 characters, then test for a 1 and remove if found.
Test for a 1?  Not understanding you there.

The ending date would be 7 characters but like you said it could be 8.  Of course like their last post it took us a while to completely understand their data.
IP logged
Raven19528
Hopeful



Thanked: 29
Posts: 284

Computer: Specs
Experience: Experienced
OS: Windows 7



« Reply #6 on: December 29, 2011, 04:57:37 PM »

Test for a 1?  Not understanding you there.

Sorry, that was a little vague. We would chop seven characters off the end, then since the only way it is 8 characters is if the month is 10, 11, or 12, they will all leave an extra "1" after chopping 7 off. That was my thought process anyway. After looking at the one string that was given again, I think the delims would be a more efficient way of axing that date anyway.
IP logged

"All things that are
Are with more spirit chased than enjoy'd" -Shakespeare
Squashman
Hopeful



Thanked: 25
Posts: 341

Experience: Experienced
OS: Other



« Reply #7 on: December 30, 2011, 10:01:41 AM »

Sorry, that was a little vague. We would chop seven characters off the end, then since the only way it is 8 characters is if the month is 10, 11, or 12, they will all leave an extra "1" after chopping 7 off.
Now I gotcha.
IP logged
Mat51
Topic Starter
Rookie



Posts: 18

Experience: Beginner
OS: Unknown

« Reply #8 on: December 31, 2011, 06:28:51 AM »


1. Are you wanting the date that is added to be a date you specify, or the date the program is ran?
2. Are you wanting to copy the files into the specified folders, or move them in there? (I.e. delete them from the source)
3. Please disregard the comment made by Candace. I too have posted work-related questions. I'm sure most people here have.

Thanks Raven,

The dates added are the dates I specify, and thats already in the code.
I want the files to be moved to the named folder.
Also, if there are any date string at the end of the file name, it should be deleted.

Many Thanks,

Matilda
IP logged
Squashman
Hopeful



Thanked: 25
Posts: 341

Experience: Experienced
OS: Other



« Reply #9 on: December 31, 2011, 07:08:39 AM »

Also, if there are any date string at the end of the file name, it should be deleted.

Many Thanks,

Matilda
So now you are saying it may or may not be there? If it isn't there are we still prefixing a date at the beginning of those files?
Did you bother to read any of our comments or questions about the existing date string you have at the end of the file name? We need clarification if the date at the end is not always a fixed length? Is there a space before the date at the end and is it the only space at the end?

I would like to give you some advice when posting questions here because it seems to take us a few days to get exactly what you are trying to do. Be very specifi about what your input looks lik and what your output looks like. Provide every possible example of what your input looks like and what the  output needs to look like.
IP logged
Mat51
Topic Starter
Rookie



Posts: 18

Experience: Beginner
OS: Unknown

« Reply #10 on: January 02, 2012, 11:28:39 AM »


We need clarification if the date at the end is not always a fixed length? Is there a space before the date at the end and is it the only space at the end?

Apologies for any misleading queries
The date at the end is not always a fixed length
And there is no space before date at the end.



IP logged
Squashman
Hopeful



Thanked: 25
Posts: 341

Experience: Experienced
OS: Other



« Reply #11 on: January 02, 2012, 11:33:39 AM »

Still didn't answer all the questions.
Are we processing files that do not have the date appended to the end of the filename?
IP logged
Raven19528
Hopeful



Thanked: 29
Posts: 284

Computer: Specs
Experience: Experienced
OS: Windows 7



« Reply #12 on: January 03, 2012, 05:26:48 PM »

Okay, then here is another couple question (as this gets more complex) When there is no date at the end is there anything that can help us identify that any numbers encoutered are belonging to the filename and not a date? I see numbers in your example, and all of the wants mixed with ambiguity of file names is making it more and more difficult to get a program to recognize exactly what you are wanting. Also, is the filename structure fairly standard, or does it at least have a fairly small maximum length? I.e. Your example ACA-810_DDR62 is 13 characters in length of a filename. Are most or all of the filenames going to be near this number, with maybe 15 or so being maximum (not including an end date string if it exists, since you want it removed)? I know this is a lot of questions, but it is necessary as the computer doesn't think like we do. You could easily tell someone what to look for as far as removing an end date string, and most people with half a brain would be able to do it. Computers and programs, not so much. At least, not so much with so little input.

Here's what we have so far:

You want to add a standard date to the beginning of all of the filenames of files in a particular directory.
You want to copy files with certain keywords into particular directories.
You want to trim any additional dates off the end of the files. (This is what is giving us problems.)

Squashman, in case I am out for an extended period, what I am hoping for is to get a max length out of the question, then, within the for loop, cut the input file name to the max length, and test for numbers, and chop if found. I've done this before by calling a loop from within the for loop that accomplishes the task, see below for the sample. Basically it would have to look for any digit (hopefully there is someway to differentiate the date digit from a name digit) and cut it away and test the next character, working from right to left.

Code: [Select]
for /f "delims=" %%F in ('dir /s /b') do (
  set OldFilePathAndName=%%~dpnxF
  set OldFileName=%%~nxF
  set FileName=%%~nF
  call :setfilename
 
  copy "!OldFilePathAndName!" "%NewFilePath%" >nul
  ren "%NewFilePath%\!OldFileName!" "!NewName!"
  echo !NewName!>>copylog.txt
)
goto :eof

:setfilename
:filepathloop
echo !FileName! | find "\" >nul
if errorlevel 1 goto :eof
set FileName=!FileName:~0,-1!
goto filepathloop
« Last Edit: January 03, 2012, 05:40:56 PM by Raven19528 » IP logged

"All things that are
Are with more spirit chased than enjoy'd" -Shakespeare
Mat51
Topic Starter
Rookie



Posts: 18

Experience: Beginner
OS: Unknown

« Reply #13 on: January 08, 2012, 04:20:22 AM »

Hi Raven and Squashman,

Thanks alot, the code works for me........ :)
IP logged
Raven19528
Hopeful



Thanked: 29
Posts: 284

Computer: Specs
Experience: Experienced
OS: Windows 7



« Reply #14 on: January 09, 2012, 02:33:38 PM »

What worked? I would imagine that you probably had to modify the code a bit to get it to accomplish the task you were looking to accomplish with it. Please post what you ended up with so we can see what worked and what modifications you made. I'm glad it worked for you though, I'm just really curious as to what worked and what needed to be changed.
IP logged

"All things that are
Are with more spirit chased than enjoy'd" -Shakespeare
Pages: [1] - (Top) Print 
Home / Microsoft / Microsoft DOS / Prefix file names « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.18 seconds with 20 queries.