Replace wildcard in fileName

January 20, 2011 at 08:35:45
Specs: Windows XP, Core2Duo/2GB
Hello everybody,


I have to download (via FTP) some files from a Unix platform to a Windows one.
When I connect to the Unix platform, I see the filename of files in this format:
AB_ASDFGHJ1234-45-56.67:78:89 and when I download the files in Windows I am getting
AB_ASDFGHJ1234-45-56.67_78_89

My first concern is why it happens so?
Moreover, is that a rule that ":" are always switched to "_" ? (Unix -> Windows)

Secondly, I would like to change the fileName of the files by removing some wildcards:
AB_ASDFGHJ1234-45-56677889
Now, being that I might have files of type :
AB_ASDFGHJ1234-45-56.67_78_89.12541
I would like to have it:
AB_ASDFGHJ1234-45-56677889.12541

So it makes the rule this way:
Leave as it is since the 18th character,
Delete the first 3 wildcards ("." and "_") <=> Replace the first 3 wildcards with 'blank'.

Can you please help me on this?

Thank you all and regards,
Pupli


See More: Replace wildcard in fileName

Report •


#1
January 20, 2011 at 08:51:25
I think maybe this will work...

for /f "tokens=1-4 delims=_" %%a in ('dir c:\mydir\AB_*.* /b') do (
ren %%a_%%b_%%c_%%d %%a_%%b%%c%%d
)

for /f "tokens=1-2 delims=." %%a in ('dir c:\mydir\AB_*.* /b') do (
ren %%a.%%b %%a%%b
)

Note not tested. You may just want to use ECHOs to see what the results would be like...

for /f "tokens=1-4 delims=_" %%a in ('dir c:\mydir\AB_*.* /b') do (
echo ren %%a_%%b_%%c_%%d %%a_%%b%%c%%d
pause
)

This might also help...

http://www.robvanderwoude.com/ntfor...

Also, Windows files must have extensions on them so Windows knows which program to open the files in. For example...

Myfile

will not open but

MyFile.txt

will open in Notepad.

You don't have to have extensions you will just be prompted to select a program when you try to open them.


Report •

#2
January 21, 2011 at 00:26:27
Thank you ace_omega ,

There is only one issue, when I have the filename of format:
AB_ASDFGHJ1234-45-56.67_78_89.12541
I would like to have it:
AB_ASDFGHJ1234-45-56677889.12541
But, applying the script will only give me back
AB_ASDFGHJ1234-45-56.677889.12541

But, being that I have just a few cases, it would not be a problem.

I have one more question.
What if now I need to "undo" the rename. Or better,
How to rename AB_ASDFGHJ1234-45-56677889
into AB_ASDFGHJ1234-45-56.67_78_89
1 - add a "." after the AB_ASDFGHJ1234-45-56
2 - and than a "_" after the AB_ASDFGHJ1234-45-56.67
3 - and finally the last "_"

thank you again,
pupli


Report •

#3
January 21, 2011 at 08:20:49
So ...

for /f "tokens=1-2 delims=." %%a in ('dir c:\mydir\AB_*.* /b') do (
ren %%a.%%b %%a%%b
)

did not work. Hmmm, when I have time I will try to make test files like yours and see if I can figure it out. You may want to try parsing the name like...

for /f "tokens=*" %%a in ('dir c:\mydir\AB_*.* /b') do (
  Set FileName=%%a
  ren %%a %FileName:~-36,20%%FileName:~-14,2%%FileName:~-11,2%%FileName:~-8,8%
)


Report •

Related Solutions


Ask Question