[solved]remove backslashes from file names?

Hi!
I have a lot of files that contain backslashes in file name, spread over many many folders.
How do I remove that character from all file names? The approaches / scripts / programs I usually work with can't handle the invalid file names (e.g. loose the '\' and then 'cant stat()' -.-").
Thanks!
edit: Argh... now I've got copies of half of the files without the "\" in the same folders, because copying did work on most but deleting only on some... also multiple \\\ because I messed up one sed line. and "echo" failed to warn me about the result, just dropping a few \ while mv didn't... or something. So confused.
Last edited by whoops (2011-02-22 00:22:58)

sisco311 wrote:#!/usr/bin/env bash
while IFS= read -rd '' file; do
dirname="${file%/*}"
basename="${file##*/}"
mv --backup=numbered -- "${file}" "${dirname}/${basename//\\/_}"
done < <(find /full/path/to/dir -depth -name '*\\*' -print0)
Thanks, that did it!
Don't know what exactly I've been doing wrong, but it seems not to happen any more since I try to do stuff with "while, read, ${}"  instead of "for, $(), echo, sed"
pulce wrote:Not sure that's the point, but backslash is an escape
Yes, I know, that was the problem. That's why those stupid things always keep either disappearing or multiplying - I guess I just suck at keeping track of what program handles them which way and depending on what.
Last edited by whoops (2011-02-22 00:15:30)

Similar Messages

  • Removing date from file name

    Hello,
    Is there any way to move all the file from one location to another and remove the datepart from filename.
    for eg:- if file name is abc_20150411.xls change to abc.xls. if file name does not contain date part then ignore it.
    Can any one suggest if its possible.
    Thank You

    Hi ,
    I have created package based on your question and decribed in detail in below post:-
    https://msbitips.wordpress.com/2015/04/12/ssis-removing-datestamp-from-file-name-when-moving-from-one-location-to-other/
    You need package code, just add comment in this thread.
    Thanks
    Prasad
    Mark this as Answer if it helps you to proceed on further.

  • Regex: Remove Date from File Names Sitewide

    I'm trying to avoid  hundreds of 301 redirects across my site. I have two kinds of links that need a regex search string which will simply remove numbers that precede text within html files.
    The existing .html files are named with text only (e.g., name.html), whereas the .jpg files have the date and text (e.g., 130415name.jpg). But the new html engine I am using creates files named like the .jpg files (e.g., 130415name.html).
    I can strip the numbers out of file names in Name Munger (Strip Characters > Characters: 0123456789).
    Now I need a regex search string that will strip the same characters within the html files.
    The changes would look like this:
    1.
    Before:
    <ul>
    <li class="previous"> <a class="paginationLinks detailText" href="../content/090914name.html">Previous</a> </li>
    <li class="index"> <a href="../index_4.html" class="detailLinks detailText">Index</a> </li>
    <li class="next"> <a class="paginationLinks detailText" href="../content/090125name.html">Next</a> </li>
    </ul>
    After:
    <ul>
    <li class="previous"> <a class="paginationLinks detailText" href="../content/name.html">Previous</a> </li>
    <li class="index"> <a href="../index_4.html" class="detailLinks detailText">Index</a> </li>
    <li class="next"> <a class="paginationLinks detailText" href="../content/name.html">Next</a> </li>
    </ul>
    2.
    Before:
    onclick="window.location.href='content/020922name.html'"
    After:
    onclick="window.location.href='content/name.html'"
    What is the regex search string for these examples (any numbers preceding any letters preceding .html)?

    Set the Search option to Source Code
    In the Find field:
    (content/)\d{6}(\w+\.html)
    In the Replace field:
    $1$2
    Select the "Use regular expression" checkbox.

  • [solved] Remove words from file using a list variable?????

    Is it possible with bash, to create a script that will scan a text file and remove words that are set in a list?
    I have a file with words like so:
    word1
    word2
    word3
    I would like to be able to set script to scan file and remove only the words (and spaces left) that are in a list,
    that is inside script. Is this possible???
    Last edited by orphius1970 (2010-04-22 12:05:45)

    sorry I am new to scripting and Have NEVER used sed.
    Can you explain a little better?
    Ok i tried it and understand a little better. However,
    It left space behind. How do I fix that?
    Also, how do I get it to save the file with the changes?
    Sorry If I seem so noobie
    Last edited by orphius1970 (2010-04-22 11:27:18)

  • [SOLVED] Removing brackets from file - python/sed

    I wrote a small python-script in order to do some manipulation of columns. I'm quite unexperienced, and i stumbled upon a problem i didn't manage to solve:
    When the script is finished with the data manipulation, everything is stored as data type "list", which implies the following form when i output the data with print: ['2321321', '321321321', '55555']. I don't want the brackets and ' (since i want to import the data into a spreadsheet). I've tried to make a loop to print out list content, but then i get everything in one column, which i don't want. (Something like: for l in line: print l )
    Is there a way to print lists without the brackets and '? I tried to solve it with sed, but my knowledge of that program is zero, and no success. My solution was to open the output in a text editor and use search and replace, which is very tedious work for 50 files.

    I think the quicker way is using the join() method:
    [andyr@roo ~]$ python
    Python 2.4.1 (#1, Apr 5 2005, 11:00:51)
    [GCC 3.4.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> items = ["one", "two", "three"]
    >>> allitems = " ".join(items)
    >>> print allitems
    one two three
    Of course, you could have "," or "t" (tabs), etc to delimit the columns rather than the space in the above example.

  • Remove LF characters from file names

    I have a folder full of files with filenames that contain LF character (ASCII code 10).  I want to use Automator's "Replace Text" funcion to remove these non printing characters from file names.  Is there a way to do it?
    If automator is not able to do this task, I will take a bash script or applescript solution as well...

    Take a look at: http://stackoverflow.com/questions/4417588/sed-command-to-fix-filenames-in-a-dir ectory
    (I changed  tr -d "\r\n" to tr -d "\n", but try both)
    for f in ~/Desktop/*
    do
        new="$(printf %s "$f" | tr -d "\n")"
        if [ "$f" != "$new" ]; then
            mv "$f" "$new"
        fi
    done

  • File type from file name

    Hi,
    Is there any standard method to get a file type from file name?
    File name can be ‘C:\test.doc’ or “C:\test’(test – is file) i.e. with or without file type extension.
    ...Naddy

    You can use the Function module PC_SPLIT_COMPLETE_FILENAME
    export paramter extension will tell the type of file
    Sample Output
    Import     COMPLETE_FILENAME     C:\TEST.TXT
    Import     CHECK_DOS_FORMAT     
    Export     DRIVE     C
    Export     EXTENSION     TXT
    Export     NAME     TEST
    Export     NAME_WITH_EXT     TEST.TXT
    Export     PATH     \

  • WCF Service and Sharepoint Form library : How i can read a access a form libray and query a item from file name and read form xml in WCF service ?

    WCF Service and Sharepoint Form library : How i can read or access a form libray and query a item from file name and read form xml in WCF service ?
    Ahsan Ranjha

    Hi,
    In SharePoint 2013, we can take use of REST API or Client Object Model to access the SharePoint objects like Form Library.
    SharePoint 2013 REST API
    http://msdn.microsoft.com/en-us/library/office/dn450841(v=office.15).aspx
    http://blogs.technet.com/b/fromthefield/archive/2013/09/05/working-with-sharepoint-list-data-odata-rest-and-javascript.aspx
    SharePoint 2013 Client Object Model
    http://msdn.microsoft.com/en-us/library/office/fp179912(v=office.15).aspx
    http://msdn.microsoft.com/en-us/library/office/jj193041(v=office.15).aspx
    With the retrieved file, we can then use XmlDocument object to parse it and get the values you want:
    http://weblogs.asp.net/jimjackson/opening-and-reading-an-xml-file-in-a-document-library
    http://stackoverflow.com/questions/1968809/programatically-edit-infopath-form-fields
    Best regards
    Patrick Liang
    TechNet Community Support

  • Need help with EXS24 "read velocity range from file name"

    I am trying to import 127 drum samples to a single key using the option shown here. The option says "Map to key dropped on and read velocity range from file name". I can find no documentation in the manuals on how to do this. What is the syntax required in the file name to make this work? I need to do several of these imports. The capability is cleary there, but I need help on how the file name should be formatted. My thanks to anyone who can help.

    Hi
    Not a direct answer to your question, but if you are doing a lot of sample mapping etc, you may want to check out Redmatica's KeyMap Pro or the simpler Keymap 1:
    http://www.redmatica.com
    CCT

  • EXS24 read root key from file name only

    Has anyone encountered this with EXS24 in Logic 7? If you set preferences to "read root key from file name only" then EXS reads the root key from the file itself when loading samples. On the other hand if you set them to "read root key from file only" then it reads the root key from the file name. Or am I just imagining this?
    P.S. if anyone from Apple is reading, could you please update EXS24? It's a bit primitive by today's standards.

    Hi
    Not a direct answer to your question, but if you are doing a lot of sample mapping etc, you may want to check out Redmatica's KeyMap Pro or the simpler Keymap 1:
    http://www.redmatica.com
    CCT

  • Cloud does not disappear from file name?

    why does it take "forever" for the cloud to disappear from file name?
    I saved a numbers document to the cloud a half an hour ago, and the cloud is still there.

    HDash-Tech,
    thanks for the tip, but since I have my iTunes Library on a NAS I have to direct iTunes every now and than via "choose library" to the folder and it doesn't make a difference...
    I think it's somehow due to my iTunes Match.  I know they do not sync audiobooks, but they mess up pretty much everything else within my library.  Songnames here and there and especially cd covers!
    Any other idea how to get it straigten out again?
    Thank,
    Daniel

  • Batch document title from file name?

    Forgive the newb question on a fairly simple matter.
    I want to create File Info: Document Titles from file names, minus the extension, for about 400 images.
    Is this possible with Batch rename, if so what am I missing?
    Thanks,

    I am unclear how a batch rename will enter data into File Info: Document Title.
    I have never used them but you might look at metadata templates.  Several sites on web on how to set them up and what they will do for you.

  • B2B identifying TP from file name and not Interchange

    We want B2B to identify trading partner from ISA/GS segment, but B2B is taking it from file name. We have property oracle.tip.adapter.b2b.edi.identifyFromTP set to "Interchange". As I understand based on the tip.property it should always take from the ISA/GS segment in dat file.
    We also have Trading Partner Identification Type set to EDI Interchange ID while setting up trading partner and it is set to the same value as Interchange Receiver Id in the Document Protocol.
    Anyone has any ideas?
    Thanks

    Hello Venkat,
    ideally this should work. Guess you have not restarted b2b after changing the tip.properties. If you still have issues, please raise an SR and also send the b2b.log in DEBUG mode.
    Rgds,Ramesh

  • How to remove DRM from files

    I thought iTunes Match was supposed to remove DRM from files

    royfrommanhattan wrote:
    I thought iTunes Match was supposed to remove DRM from files
    It doesn't actually  "remove" anything.  But it does allow you to delete the DRM versions and download non-DRM versions, if available.
    Go to this document, and read the section on "Can I upgrade my previously purchased music to iTunes Plus?":
    http://support.apple.com/kb/HT1711

  • How can I extract metadata from file names?

    If I want to extract metadata from file names? How can I do that? I want to read through the file names and when I get to a certain character ("-"), I can take the string just before that character and store it in a column in SharePoint. Is this
    do-able through scripting? 

    If I want to extract metadata from file names? How can I do that? I want to read through the file names and when I get to a certain character ("-"), I can take the string just before that character and store it in a column in SharePoint.
    Is this do-able through scripting? 
    You should be able to leverage the split method.
    In PowerShell It would look like:
    # Gather the file name
    $file = "myawesome_filename-Month-Day-Year-Ect.doc"
    #split the file name by the "-" character
    $file = $file.split("-")
    # Use a foreach Loop to gather the individual items.
    foreach ($item in $file) {
    write-host $item
    #Outputmyawesome_filename
    Month
    Day
    Year
    Ect.doc
    # If you want to only grab the first item, you can do $file[0] <-- powershell starts counting with zero base.
    $file[0]
    #output
    myawesome_filename
    Entrepreneur, Strategic Technical Advisor, and Sr. Consulting Engineer - Strategic Services and Solutions Check out my book - Powershell 3.0 - WMI: http://amzn.to/1BnjOmo | Mastering PowerShell Coming in April 2015!

Maybe you are looking for

  • STMS: Transport control program tp ended with error code 0232

    Dear ERP Gurus, I just encountered problem with STMS in my PRD system. The import is just stuck up on "tp connecting to database". It won't continue unitl the system gives me this error message: Transport control program tp ended with error code 0232

  • Html page in body

    I can send mail with simple text in the body. But when i am sending html contents in the body i got blank content in the email body. This is my code. MimeMessage m = new MimeMessage(session); if(From != null | To != null) Address from = new InternetA

  • Finding the Sprite number if we give the member name

    Hi every one I want to find the spritenum based on the member name supplied for example i have a text field the member name of this field is "txtFirstName" Now if i want to find the sprite num through code then how should i go about it. I couldn't th

  • After an update from 9i

    I used this query: SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE, DATA_PRECISION "PREC.", DATA_SCALE SCALE FROM USER_TAB_COLUMNS WHERE DATA_TYPE = 'NUMBER' ORDER BY TABLE_NAME, COLUMN_NAME ; and I got several rows of this garbage: TABLE_NAME COLUMN_NAME

  • Using the notlike in powershell

    I have written several similar scripts using the -contains and -Like with no issue. However I ha not trying to apply that using the -notlike it however does not give the desires response. if ($strUser.memberof -notlike "*NSeries*" -and $strUser.scrip