<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Hello everyone, I have a directory with 40 files. File names are divided into prefixes. I need to rename the prefix k3241 according to the name in the... in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/hello-everyone-i-have-a-directory-with-40-files-file-names-are/m-p/29530#M21253</link>
    <description>&lt;P&gt;Hi @welder martins​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How are you doing?&lt;/P&gt;&lt;P&gt;Thank you for posting that question. We are glad you could resolve the issue. Would you want to mark an answer as the best solution?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
    <pubDate>Wed, 13 Apr 2022 14:39:11 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2022-04-13T14:39:11Z</dc:date>
    <item>
      <title>Hello everyone, I have a directory with 40 files. File names are divided into prefixes. I need to rename the prefix k3241 according to the name in the...</title>
      <link>https://community.databricks.com/t5/data-engineering/hello-everyone-i-have-a-directory-with-40-files-file-names-are/m-p/29525#M21248</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="Template"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2130i981DC7FDCDDE207C/image-size/large?v=v2&amp;amp;px=999" role="button" title="Template" alt="Template" /&gt;&lt;/span&gt;Hello everyone, I have a directory with 40 files.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;File names are divided into prefixes. I need to rename the prefix k3241 according to the name in the last prefix.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I even managed to insert the csv extension at the end of the file. but renaming files based on various prefixes is the tricky one. Can anybody help me. I will be posting the image of the code that was created.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;/*
This code inserts the csv extension in the filename.
*/
path ="/dbfs/tmp/data/dadosjuridicos/descompactados"
for i in os.listdir(path):
    files = os.path.join(path,i)
    split= os.path.splitext(files)
    if split[1]=='.COMPANY':
       os.rename(files,split[0]+'COMPANY.csv')
    if split[1]=='.ESTABLISHMENT':
       os.rename(files,split[0]+'ESTABLISHMENT.csv')
    if split[1]=='.PARTNER':
       os.rename(files,split[0]+'PARTNER.csv')&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Feb 2022 12:55:32 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/hello-everyone-i-have-a-directory-with-40-files-file-names-are/m-p/29525#M21248</guid>
      <dc:creator>weldermartins</dc:creator>
      <dc:date>2022-02-04T12:55:32Z</dc:date>
    </item>
    <item>
      <title>Re: Hello everyone, I have a directory with 40 files. File names are divided into prefixes. I need to rename the prefix k3241 according to the name in the...</title>
      <link>https://community.databricks.com/t5/data-engineering/hello-everyone-i-have-a-directory-with-40-files-file-names-are/m-p/29526#M21249</link>
      <description>&lt;P&gt;Hey there! Thanks for your question. I'm sorry to hear you're having difficulty. Let's see what your peers have to say. &lt;/P&gt;</description>
      <pubDate>Fri, 04 Feb 2022 19:21:35 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/hello-everyone-i-have-a-directory-with-40-files-file-names-are/m-p/29526#M21249</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-02-04T19:21:35Z</dc:date>
    </item>
    <item>
      <title>Re: Hello everyone, I have a directory with 40 files. File names are divided into prefixes. I need to rename the prefix k3241 according to the name in the...</title>
      <link>https://community.databricks.com/t5/data-engineering/hello-everyone-i-have-a-directory-with-40-files-file-names-are/m-p/29527#M21250</link>
      <description>&lt;P&gt;Similar to the result of this code, but to change files.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;path = 'k3250.seqy0.company.csv'
&amp;nbsp;
path1 = path.replace("k3250", "company")
&amp;nbsp;
print(path1)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Feb 2022 13:05:38 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/hello-everyone-i-have-a-directory-with-40-files-file-names-are/m-p/29527#M21250</guid>
      <dc:creator>weldermartins</dc:creator>
      <dc:date>2022-02-08T13:05:38Z</dc:date>
    </item>
    <item>
      <title>Re: Hello everyone, I have a directory with 40 files. File names are divided into prefixes. I need to rename the prefix k3241 according to the name in the...</title>
      <link>https://community.databricks.com/t5/data-engineering/hello-everyone-i-have-a-directory-with-40-files-file-names-are/m-p/29528#M21251</link>
      <description>&lt;P&gt;I managed to solve it using the code below. &lt;/P&gt;&lt;P&gt;thank's&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;if split[1]=='.COMPANYCSV':
        os.rename(files,files.replace("K3241", "COMPANY")) &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Feb 2022 18:31:24 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/hello-everyone-i-have-a-directory-with-40-files-file-names-are/m-p/29528#M21251</guid>
      <dc:creator>weldermartins</dc:creator>
      <dc:date>2022-02-08T18:31:24Z</dc:date>
    </item>
    <item>
      <title>Re: Hello everyone, I have a directory with 40 files. File names are divided into prefixes. I need to rename the prefix k3241 according to the name in the...</title>
      <link>https://community.databricks.com/t5/data-engineering/hello-everyone-i-have-a-directory-with-40-files-file-names-are/m-p/29529#M21252</link>
      <description>&lt;P&gt;@welder martins​&amp;nbsp;- Thank you for sharing all this. You are fantastic!&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 16:10:19 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/hello-everyone-i-have-a-directory-with-40-files-file-names-are/m-p/29529#M21252</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-02-09T16:10:19Z</dc:date>
    </item>
    <item>
      <title>Re: Hello everyone, I have a directory with 40 files. File names are divided into prefixes. I need to rename the prefix k3241 according to the name in the...</title>
      <link>https://community.databricks.com/t5/data-engineering/hello-everyone-i-have-a-directory-with-40-files-file-names-are/m-p/29530#M21253</link>
      <description>&lt;P&gt;Hi @welder martins​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How are you doing?&lt;/P&gt;&lt;P&gt;Thank you for posting that question. We are glad you could resolve the issue. Would you want to mark an answer as the best solution?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2022 14:39:11 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/hello-everyone-i-have-a-directory-with-40-files-file-names-are/m-p/29530#M21253</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-04-13T14:39:11Z</dc:date>
    </item>
  </channel>
</rss>

