Rename Filename removing end-part
Hi,
I have around 200 txt files in a directory, all files have a "_" and a datestamp in the end of the filename. Is there any single-line command available that i can use to eliminate the "_" + date-part from the file names?
samples:
a1transactions_20140207.txt
b2post_20140207.txt
w32records_20140207.txt
You can see filenames are varying in number of letters in beginning, but the end-part always same which is "_yyyyMMdd". I want to remove this end-part.
After the rename, files should name like:
a1transactions.txt
b2post.txt
w32records.txt
Hi,
Here's one method:
$strings = 'a1transactions_20140207.txt','b2post_20140207.txt','w32records_20140207.txt'
foreach ($string in $strings) {
$fixedString = $string.SubString(0,$string.IndexOf('_')) + '.txt'
$fixedString
EDIT: This is probably more on target for what you're trying to do (sorry, didn't read the post all of the way...)
Get-ChildItem *.txt | ForEach {
$fixedString = $_.Name.SubString(0,$_.Name.IndexOf('_')) + '.txt'
Rename-Item -Path $_.FullName -NewName $fixedString
Don't retire TechNet! -
(Don't give up yet - 12,575+ strong and growing)
Similar Messages
-
How to remove end of line from string?
Hello,
I'd like to remove ends of line from the string. I've tried:
static final Pattern END_LINE_PATTERN = Pattern.compile("$+");
strBuf.append(input);
Matcher m = END_LINE_PATTERN.matcher(input);
int startIndex = -1;
int endIndex;
while (m.find()) {
startIndex = m.start();
endIndex = m.end();
if (endIndex == strBuf.length() - 1) break;
if (startIndex > -1) {
strBuf.setLength(startIndex);
}For strings "hello\n" and "hello\r" it works properly, but for string "hello\n\n" I get first occurrence at index 6 (at second \n), so as the result I get "hello\n". For the string "hello\r\n" I get first occurrence at index 5 (it's OK), but the end index is 5 as well, and the next occurrence I get at index 7, which doesn't give me any sense.
Hope somebody can help me.
AgataWhat you're trying to do is remove one or more line separators from the end of a string ("\n", "\r", and "\r\n" each count as one line separator, but "\n\n" is two line separators). This is all you need to do: str = str.replaceAll("[\r\n]+$", ""); "$" doesn't match any characters, line separators or otherwise; it matches the position at the end of the string. In MULTILINE mode, it also matches the position before a line separator, but it still doesn't match the separator itself.
-
i have this data
ELECT [item_id] ,[f2] from [Regions]
1. ُEgypt
1.1. Cairo
1.1.21. New Cairo
i want to remove last part
like in Egypt remove 1.
and on Cairo remove last 1.
and on New Cairo last 21.Try:
DECLARE @City TABLE ( CityName varchar(100));
INSERT @City VALUES
('1. Egypt'),
('1.1. Cairo'),
('1.1.21. New Cairo'),
('1.1.21.5. Alexandria')
-- SELECT STUFF('abcdef', 2, 3, 'ijklmn');
SELECT
CityName, RenumberedCityName=
LTRIM(STUFF(REVERSE(SUBSTRING(SUBSTRING(REVERSE(CityName), CHARINDEX('.', REVERSE(CityName),1)+1,LEN(CityName))+'.',
CHARINDEX('.',SUBSTRING(REVERSE(CityName), CHARINDEX('.', REVERSE(CityName),1)+1,LEN(CityName))+'.'),len(CityName))),1,1,'')+SPACE(1)+
REVERSE(LTRIM(RTRIM(LEFT (REVERSE(CityName), CHARINDEX('.', REVERSE(CityName),1)-1)))))
FROM @City WHERE CHARINDEX('.',CityName) > 0;
CityName RenumberedCityName
1. Egypt Egypt
1.1. Cairo 1. Cairo
1.1.21. New Cairo 1.1. New Cairo
1.1.21.5. Alexandria 1.1.21. Alexandria
-- USING hierarchyid method
SELECT
CityName, RenumberedCityName=
LTRIM(REPLACE(STUFF(CONVERT(hierarchyid,'/'+REPLACE(LEFT(CityName, CHARINDEX(' ', CityName)-1),'.','/')).GetAncestor(1).ToString(),1,1,''),'/','.')
+SPACE(1)+REVERSE(LTRIM(RTRIM(LEFT (REVERSE(CityName), CHARINDEX('.', REVERSE(CityName),1)-1)))))
FROM @City WHERE CHARINDEX('.',CityName) > 0;
CityName RenumberedCityName
1. Egypt Egypt
1.1. Cairo 1. Cairo
1.1.21. New Cairo 1.1. New Cairo
1.1.21.5. Alexandria 1.1.21. Alexandria
Kalman Toth Database & OLAP Architect
SQL Server 2014 Design & Programming
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012 -
Rename files while retaining part of camera filename
Hello, I've just switched from Windows to OS X and I'm running a trial of Aperture. It's great so far, much better than Nikon's own RAW software (Capture NX).
However, I can't figure out how to rename imported files while also retaining part of the original filename. The images come off of the camera like this:
DSC_3497.nef
I want to retain the unique number that the image already has, but reference the camera used, and also prefix a digit to the original numeric string:
D3X_63497.nef
In Aperture's "File Naming" dialog, I don't see a way to split the existing filename in this way. It looks like I can only use the full Master File Name. Any suggestions?
Message was edited by: sempervirentI actually found two free applications that do exactly what I need.
One is a standalone app:
http://www.macupdate.com/info.php/id/33659/rename
The other runs as a native Mac service:
http://www.versiontracker.com/dyn/moreinfo/macosx/75183804
I'd still prefer to do this directly in Aperture when images are imported, so if anyone has a solution, please let me know.
Message was edited by: sempervirent -
Using iPhoto '09/8.1.2 on a MacBookPro, with 40,000+ photo library, having the (apparently common) problem of CD burn errors (with Toast and with Disk Utility) when 2 photos end up having the same underlying filename assigned by the camera. To try to avoid this, I want to retitle pictures within iPhoto so I can utilize the "use title as filename" option when exporting (because I guess I can't burn CDs from WITHIN iPhoto because of this problem, right?). I was hoping to create new titles that were a combination of the existing 4 digit filename assigned by the camera, combined with new descriptive text (either date, or event title would be fine), and hoping to save time by using Batch Change (which I've never tried - just seen it mentioned here in perusing discussions). I've also seen reference to "Automator" (which may be over my head), but again not sure if that can be used within iPhoto to combine existing/new title text. (Also, I saw mention of a script written by Toad at Toad Hall site, but the link to it was bad - may be over my head, also: never tried a "script" before...) Thanks in advance!
No. Coming out of iPhoto you're limitied to the Title, real file name, Album name or (in the Export window) Text with or without sequential number.
However, if you export out with the orignal file name to a folder you can use a file renaming app to add whatever common text to the beginning of the file name so you would get XXXX XXX-IMG 1234.jpg. Some renamers can remove the IMG bore adding the text at the beginning.
The app that I use and like best is Name Mangler. Very powerfull.
OT -
Itunes renamed filename as tracks?
Apple itunes cannot use filename to import songs, it uses tracks instead?
The field <file name>, for all my mp3 is apparently NOT used by iTunes, for sorting. As a conclusion my library is totally messed up. I need some help...
Here the details:
I have organized my audiobooks for years, in this way:
file-name: D01 T01.mp3 then D01 T02 then ....then Dn Tm.
No id3 tag.
D01 T01.mp3 means the first track on Disc 01
D05 T14 means the 14th track on Disc 05
Usually audio books contain from 1 to 5 or 6 CDs
Across the years, i ripped all my mp3 with the same structure.
I put album info only on the folder name. For example, my last audio-books set was from Brian Tracy.
For the folder name I chose "Brian Tracy - Psychology of Selling"
The content includes
file-name: D01 T01.mp3 up to D05 T10.mp3
The software I used (Media Monkey) also filled automatically these fields:
title: track 01 up to track 10 for disco 01, then again track 01 to track 10 for disc 02, etc.
I have started to use iTunes since November. But every time I try to import I see that:
- file names are TOTALLY ignored
- I end up having 4 (FOUR) mp3 files called track 01, then another 4 (FOUR) MP3 files called track 02...and so on until track 10...a completely mess!
Since <file name> field (D01 T01.mp3) is apparently NOT used by iTunes, the conclusion is that my library is totally messed up.
Additionally iTunes imports the folder WITHOUT Looking at folder name, so all folders, in iTunes, show as "unknown artist , unknown album". This second issue is solved by me by manually editing the folder name and artist name (using "getinfo" function)
Question:
can somebody explain to me how can I force iTunes to import and sort my file using the FILENAME field (D01 T01.mp3) ? Instead of title field (track 01) ?
Any help is heartily appreciated!
SAFirst do you have the original files in their original folders? If iTunes has already swallowed them up and rearranged them there's not much I can suggest. Regular music would be susceptible to MusicBrainz Picard Tagger but that is unlikely to be the case in this instance. If you still have them in their original folder layout stored outside the iTunes Media folder then turn off *Copy to iTunes Media folder when adding to library* (Edit > Preferences > Advanced) so that iTunes points to the original files rather than copies it creates based on the partial information. It's proably also wise to turn off *Keep the iTunes Media folder organised* until you are cetain that iTunes has enough information to move all your files to sensible places when it tries to organise them.
Can I confirm that each album is in a folder of the form *<Artist|Author> - <Album Title|Book Title>* and each file is in the form *D## T## <Title>.<ext>* ? If so then using the pattern *<Artist> - <Album>\D<Disc#> T<Track#> <Title>* with MediaMonkey's Auto-Tag From Filename feature should work. After updating the tags you'd either need to remove & reimport the tracks or use my UpdateTagInfo script. Alternatively I could create a special version of the TagFromFilename script to do both jobs in one...
tt2 -
Fnd_user_pkg.updateuser - Remove End Date from Users
As part of an upgrade, we need to end-date the vast majority of our users.
I've used the fnd_user_pkg.updateuser API to populate the end_date on the fnd_user table.
However, when I've come to test removing the end-date, I can't seem to do it. In the example below, the end_date remains populated.
DECLARE
CURSOR usercur
IS
SELECT fu.user_name
FROM apps.fnd_user fu
WHERE user_name = 'TEST_ACCOUNT';
BEGIN
FOR myuser IN usercur
LOOP
fnd_user_pkg.updateuser(
x_user_name => myuser.user_name
, x_owner => 'CUST'
, x_end_date => NULL
END LOOP;
END;On the example on this post:
http://apps2fusion.com/forums/viewtopic.php?f=99&t=108
They removed the end-date via:
x_end_date => SYSDATE + 10000);
However, that's not really removing the end date, it's just setting it to a long time in the future.
I wondered if I might be missing something obvious?
Any advice much appreciated.
ThanksOnly obvious thing you are missing is that you have posted this to the wrong forum, you need to be on e-business forum.
BTW - have you tried re-setting the password at the same time?
regards,
Robert. -
Renaming filenames and case-sensitivity: a race condition in the OS?
There appears to be a curious set of circumstances where the OS doesn't allow you to rename a file where the only changes are case-sensitive. For example, "foo.JPG" to "foo.jpg". You can see an example using the command-shell "tcsh". Start this shell (type "tcsh" at any command prompt), and then type:
% touch foo.JPG
% mv foo.JPG foo.jpg
overwrite foo.jpg? (y/n [n])
Now, you may think it's no problem because few people use tcsh, but the problem is more systemic that should be addressed because I'm finding the problem at a programming level as well. The simplistic tcsh example illustrates the problem: the internals of tcsh call the OS-layer library function rename(2) to move or rename a file. However, something in the OS that reports back that the new filename exists (even though it doesn't) Because it sees foo.JPG, and it doesn't differentiate letter case, it thinks foo.jpg exists, so it returns an error to the calling program. In this case, it's tcsh, which is what prompts the user to overwrite. It doesn't matter what you answer, the result is the same. If you say yesthe OS doesn't see them as different, so it doesn't do anything.
If you're a programmer, you can see this happen for yourself by writing a small program that does the same thing:
#!/usr/bin/perl
if (!rename "foo.JPG", "foo.jpg") {
print "Error: $!\n";
This simple perl script just calls the rename(2) library call, which is part of the OS.
What I don't understand is why this error happens, when, and how to get around it. Obviously, other programs that rename files don't have this problem. The default shell, bash, doesn't have a problem either--even though tcsh (also a similar command-line shell) does. In fact, most programs don't have this problem. But as a programmer, I'm not sure what I should be doing. This exact same perl script (and correlating C programs) work perfectly well on all other unix platforms I've tried.
G5 Mac OS X (10.4.5)It's not at the os layer, it's at the filesystem
layer. The filesystem you have is not case sensitive.
well, the filesystem is part of the operating system, although it's clearly only one component of it. In fact, one of the primary defining characteristics of unix is how the filesystem works, albeit there are variations of implementation. But this is a nit=picking point.
As to the issue of whether the filesystem truly is case-insensitive, that isn't so clear. I can rename a file from foo.JPG to foo.jpg easily in the Finder (just click and edit a file to change it's name from upper to lower, or mixed), and the new name you give it DOES change. similarly, I can do this with virtually any other app that has a file-finder style dialog box. Why I can't do it with the shell (or at an API level) is the real mystery, and there is no doc on the subject that I'm aware of. Clearly, the OS is preserving the change somewhere, somehow. the question is, who's doing it? (and if it's not part of the filesystem, why?)
It could be that some other layer is sitting on top of the filesystem that is overseeing such actions, and is preserving the case of the filenames, but this is such a huge waste of time and work, all for a "feature" whose value is still as yet unclear to me.
If it is, as you say, that "my version" of the filesystem happens to be case-insensitive, I'd love to know where that came from, and what the rationale was behind it. And, of course, how to get some version of the filesystem that doesn't have this feature. I've been working with unix systems at every layer since 1983, and have never run into such a thing before.
dan -
Can I batch rename to remove prepended characters?
I know the basics of batch renaming files, but can't seem to figure out if this is possible:
I have a number of files scattered across different projects and folders.
These files are named ABC-DEF-xxxxxxx
The xxxxxxx is unique to each file, and non-sequential (sometimes just text words).
So I am wondering is if there a way to batch remove the "ABC-DEF-" from the master file name and leave everything else in the name unchanged?
I should say...without doing a tremendous amount of work like exporting the files from Aperture, changing the names somehow, then re-importing (which I think would be lots of work, esp since the files are scattered across different projects/folders).
Thanks much everyone!This script will rename all the selected versions in the form XXX-YYY-FinalName to FinalName
Doesn;t matter what XXX and YYY are or how long they are as long as the format is exactly three groups of chars separated by a dash.
tell application "Aperture"
set imageList to (the selection)
if imageList is {} then
error "Select IMages."
end if
set {oldTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "-"}
repeat with i in imageList
set n to (name of i)
set name of i to text item 3 of n
end repeat
set AppleScript's text item delimiters to oldTID
end tell
to run it select all the text in the box above right click it and select make new applescript. This will copy the script into the AppleScript editor.
Start Aperture and select the images you want to rename. I strongly advise you do this first on a test library to make sure it is doing want you want. Export some of the images as a new library and test with that.
Note this will only change the version names no the original file names. If you also want to change the original file names once the versions are renamed select them and run MetaDatat->Batch Change. Select Version Name Format: Current Version Name and select the Apply to Originals checkbox. -
Rename Filename using FTP adapter
Hi All,
I have a simple file to file scenario with renaming the filename of the file at the target.
Source Filename - ABC
Target Filename (Expected) - ABC_pqr
I am using adapter specific message attributes to generate filename as '%filename%_pqr' as target filename, but only the filename 'ABC' appears in the target filename and additional '_pqr' is neglected.
Is there a way by which this can be achieved? I know, there is a option of using OS Command to rename the file at source and than use the filename.
Are there any other options, by which it can be achieved?
Thanks for your help in advance.
Regards,
AshishHi Ashish,
Use Dynamic configuration. Here is the Code: Map to the target root node.
public String Filename(String a,Container container)
String b; // Target file Name
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey keyHeader1 = DynamicConfigurationKey.create( "http://sap.com/xi/XI/System/File", "FileName");
b = /* Here the condition to rename the file
conf.put(keyHeader1, b);
return "";
Thanks, -
How to create multiple copies of a file with renamed filenames
hi,
I want to create multiple copes of a file [ say abc.docx] which has 3.5 MB of size and want to rename it through power shell.
so, in the end, i want to get abc_1.docx,abc_2.docx, abc_3.docx ....abc_10.docx in the same folder with the same size. i mean, after running the ps script i should get the foldwer size set to 35 MB .
can anyone help, how to achieve this?
I am newbie in powershell.
i tried the below :
$File = Get-ChildItem -Path "D:\ABCFolder\" -Filter Copying.bat -Recurse
for($i = 0; $i -lt $File.Count; $i++)
Copy-Item $File[$i].FullName ("D:\ABCFolder\" + $File[$i].BaseName + $i +".doc")
help is appreciated!but the below one didnt work:
$File = Get-ChildItem -Path "D:\ABCFolder\" -Filter Copying.Bat -Recurse
for($i = 0; $i -lt $File.Count; $i++)
1..10 | Copy-Item $File[$i].FullName "$($File[$I].DirectoryName)\$($File[$i].BaseName)_$_$($File[$i].Extension)"
am getting the below erro when executing this code:
$File = Get-ChildItem -Path "D:\mfolder\"
$count = $file.Count
for ($x = 0; $x -lt $count; $x++)
$ext = $file[$x].Extension$name = $file[$x].BaseName
for($i = 0; $i -lt 100; $i++)
Copy-Item $File[$x].FullName -destination "D:\mfolder\$name_$i$ext"
/////////////////////////////error below://///////
At D:\mfolder\createcopies2.ps1:7 char:27
+ $ext = $file[$x].Extension$name = $file[$x].BaseName
+ ~~~~~
Unexpected token '$name' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken -
Remove XI-part of SOAP Header in Axis Adapter
Hi folks!
We are running a PI 7.11 and use the SOAP Axis Sender Adapter in a synchronous SOAP Web Service scenario. Our challenge is that in our response we definitely need a SOAP Header tag, but it should be empty like this <soapenv:Header/> or this <soapenv:Header></soapenv:Header>
We tried to achieve this with the Axis Handler com.sap.aii.axis.soap.HeaderRemovalHandler. But regardless of the parameters we provide to this handler it always removes the complete SOAP Header. On sample is to remove the PI-specific Main header tag from SOAP Header:
name.1=Main
namespace.1=http://sap.com/xi/XI/Message/30
We also tried it only with namespace. But always the same sh... happens: The SOAP Header is removed completely.
Any ideas?
Thanx very much in advance!
Regards,
VolkerHi Stefan!
Thanx for your reply. We found that Axis handler mentionedby me in SAP Note 1039369 "FAQ XI Axis Adapter" .
But please tell me how to parameterize the java:com.sap.aii.axis.xi.XI30InboundHandler to ensure that the XI part of SOAP header is removed, but not the complete SOAP header.
Thanx in advance!
Regards,
Volker -
Remove Icon part of Advanced DataGrid Header
Hi,
I would like to remove the Icon part of the header in the AdvancedDataGrid. I am however unable to find how to do this.
In the header of every column in the AdvancedDataGrid, on the right side, it shows a pipe symbol and some spacing. After a bit of digging, I found that it was the Icon part of the header. However, I do not use icons in my headers, and I need to use the complete header space for text. This is why the icon part needs te be removed.
Does anyone have an idea how we can do this?
Thanks in advance
Ronald Kamp
Flex/Java Developer at Ordina BelgiumHi Stefan!
Thanx for your reply. We found that Axis handler mentionedby me in SAP Note 1039369 "FAQ XI Axis Adapter" .
But please tell me how to parameterize the java:com.sap.aii.axis.xi.XI30InboundHandler to ensure that the XI part of SOAP header is removed, but not the complete SOAP header.
Thanx in advance!
Regards,
Volker -
Please tell me how to rename a text file in form (6.0i) without using host command.
It's because there are some problems to use host in WIN2000 environment and the filename is restricted to 8.3 format.
Thanks.Yes it is very true that in WIN 2000 there is a problem of 8.3 fromat.
You can use Windows System Interface routines
Win_Api_Utility.Copy_File routine
for eg.
Win_Api_Utility.Copy_File(v_file_chosen,fname_to_copy,true,false);
Here v_file_chosen is source filename with full path
and fname_to_copy is destination file name .
In this API you can find out other function also.
For that u need to attach d2kwutil.pll file in ur forms.
Find it out in ur system if not there let me know i ll mail
this file u across. -
Satellite A55 How to remove Bottom part of the notebook?
I need to remove the bottom of my A55. I've removed all the visible screws but something is hanging up in the battery area. Can someone please help me?
Thanks so much.Hi
Peter you are the best one. :)
Libits maybe is some part under keyboard that should be removed before.
Bye
Maybe you are looking for
-
Purchase Requisitions, Purchase Orders and Receipts
Hello all, The following is the sequence for Purchasing Purchase Requision -> Purchase Orders -> Receipts However I have a requirement to bring in the related Purchase requisions,purchase orders and receipts from 11i into R12 instance.I can do that u
-
Why was this ever changed? Why was it changed without asking/polling? Why is it so spread out? Why would it be purposely made, to make it difficult to browse the web? Why would you sabotage your own product?! I am NOT the only person out here asking
-
SYSTEM table space is critical
Hi, Generally we will not add any datafiles for UNDO table space because it is oracle managed tablespace.For SYSTEM table shall I add datafile if it reaches threshold value or not? Regards, ARNS.
-
Enhance the Time Dependent Tab of the Asset Master AS01
Hi, My requirement is to enhance the Asset Master Client dependent Tab transaction AS01. I have added a field in the ANLZ through some Append Structure. And added that field in the Custom Screen. After doing the functional config that field is visibl
-
How to make connection to ORACLE 7.1.6
Hi, May I have suggestions on how to make connection to ORACLE 7.1.6 on UNIX box? Thank you very much for help! Jane