I would like to copy a file, but I want the new file to be named something different, like having a (1) next to the name without changing the extension.   Here is my code:   import shutil from tkinter import * from tkinter.filedialog import askopenfilename import os   filename = askopenfilename()  file_name, file_extension = os.path.splitext(filename)  dec = "_dec"  newfile = file_name + dec   copied = str.join(newfile, file_extension)   shutil.copy(filename, copied )  master = Tk()  w = Message(master, text="Copied!", width = 100) w.pack()  mainloop()   How would I get filename to have a (1) at the end of the name without touching the extension?
3386
Is there a function to extract the extension from a filename?
106414
I need to batch rename bunch of files with id in name, adding a constant number to id   &lt;id&gt;-xxx.txt =&gt; &lt;id+shift&gt;-yyy.txt   Any ideas how to make it? Some awk maybe?
44059
I have one input file and run some command but want the output to be saved with the same name as the input file has.  I tried below command but it makes the output file blank:  cat file1 | grep "YISHA" &gt; file1
44876
I have a situation where I have the following:  file01.ext . . . file99.ext file100.ext . . .   And I want to (using rename ) insert the '0' for the files 01-99 (so that they become 000-099) but not modify files larger than 100. Which expression should I use and what is a good source on learning regular expressions such as these?   On Windows I would have used Total Commander's multi rename function which has a very simple renaming syntax. Are there some good alternatives for that tool (multi-rename) for Ubuntu?
37878
I somehow managed to create a file that doesn't seem to have a filename. I found some information regarding how to get more details of the file in the following   However, I tried some of the suggestions listed and can't seem to delete the file. I'm not sure what I did to create it, but it happened while trying to copy an xml file.   Some info on the file is as follows;  &gt; ls -lb total 296 -rw-r--r--   1 voyager  endeavor  137627 Jan 12 12:49 \177  &gt; file * :               XML document  &gt; ls -i  417777      I tried to find using the inum switch and then pipe that to rm as that seemed like the most foolproof way of getting rid of it. However, the example given at the bottom of the thread linked below failed for me. Example was:  &gt; find -inum 41777 -exec ls -al {} \; find: illegal option -- i find: [-H | -L] path-list predicate-list   so I tried using the path list first like the following, but that didn't work either:  &gt; find . -inum 41777 -exec ls -al {} \;   I'm not sure what the non-printable character \177 is or how I can pass that to an rm command, but I really want to make sure I don't mess up any other files/directories in my attempt to delete this file.
62543
I have a .txt that can be exemplified like this:  NAME | CODE name1 | 001 name2 | 001 name3 | 002 name4 | 003 name5 | 003 name6 | 003   I need to write a script to split this file according to the CODE column, so in this case I'd get this:  file 1: NAME | CODE name1 | 001 name2 | 001  file 2: NAME | CODE name3 | 002  file 3: NAME | CODE name4 | 003 name5 | 003 name6 | 003   According to some research, using awk would work:  $ awk -F, '{print &gt; $2".txt"}' inputfile   The thing is, I also need to include the header to the first line and I need the file names to be different. Instead of 001.txt, for example, I need the file name to be something like FILE_$FILENAME_IDK.txt.
84635
Does anyone know if it's possible to change a setting so that the full file name is selected when you rename a file in newer versions of Windows?  (i.e. to match the behavior in Windows XP).  Currently it doesn't select the extension, so I have to do it manually.
53293
I want to rename the number 1->picture (32) with python not the number 2->picture with the (3745), can someone help me with that ?
98998
I need to do create a file with a filename such as :&gt;?, is this possible somehow? Windows stops it.
96168
I'm trying to create a batch file (to run in the background) that will copy a single file without overwriting any file in the destination with the same name, and then move the file, again not overwriting if there is a file in the destination with the same name?  I'm using this at the moment, but it is overwriting.  copy %1 dest move %1 dest
117822
How can I strip out some text from filenames in a folder?  I'm currently attempting:  rename s/"NEWER_(.*?)"//g *   But nothing it getting renamed  I have a parent folder, with a bunch of sub-folders, within are files, that OneDrive thought would be a great idea to append a " (NEWER_timestamp)" to, and I'd like to remove that.  Example File Names:  getyou.ico (NEWER_1417529079.87) o7pm.ico (NEWER_1417529184.89) o7th.ico (NEWER_1417529135.81)
42913
Is there a convenient way to rename a file (or dir) without redundantly repeating the path or directory-changing to it?  For example …  mv -some_flag db/migrations/abc_201911201243.php abc_20191101090000.php   … to rename the file without moving it out of that directory.  I looked into the man pages for mv, rename and rsync but didn't find anything, so I'm wondering if there is by chance a non-obvious trick to do this.
66866
I am trying to put together a Powershell script that will:  -Search recursively from a root directory -Exclude files with existing "yyyyMMdd " file name prefix -Rename the files not excluded above with ""yyyyMMdd " file name prefix based on their specific LastWriteTime  Note: ideally, this script should include all file type extensions  I have tried myself, but it would seem to be above my head, as my attempts are not going well.  Thanks, in advance.    #StampMe.ps1 param( [string] $fileName)  # Check the file exists if (-not(Test-Path $fileName)) {break}  # Display the original name "Original filename: $fileName"  $fileObj = get-item $fileName  # Get the date $DateStamp = get-date -uformat "%Y-%m-%d@%H-%M-%S"  $extOnly = $fileObj.extension  if ($extOnly.length -eq 0) {    $nameOnly = $fileObj.Name    rename-item "$fileObj" "$nameOnly-$DateStamp"    } else {    $nameOnly = $fileObj.Name.Replace( $fileObj.Extension,'')    rename-item "$fileName" "$nameOnly-$DateStamp$extOnly"    }  # Display the new name "New filename: $nameOnly-$DateStamp$extOnly"   I am hoping to change the line:  $DateStamp = get-date -uformat "%Y-%m-%d@%H-%M-%S"   To be LastWriteTime instead of get-date, but I have no idea how to make this happen.  This code (from another Super User question):  Get-ChildItem "Test.pdf" | Rename-Item -newname {$_.LastWriteTime.toString("yyyyMMdd") + " Test.pdf"}   ...successfully renames a single file, but I can't seem to integrate this into the larger script.    With regards to running the above recursively, I have tried this (also from ):  foreach ($file in get-ChildItem *.* -recurse) { ./StampMe.ps1 $file.name }   Which succeeds to apply the PS script to files in the root directory, but fails to apply to any files in the sub-folder tree that propagates from the root directory.
35201
I have files in the following format: x1 x2 ... x10 x11 ... x101 ...  I want to rename these files, so they all have the same name length: x001 x002 ... x010 ...  I can do this with files, that don't have the non-numeric prefix (just using sort -n followed by a while read x;), but sort doesn't recognize the numeric value, when it's not on the beginning of the file-name.
48194
With the commands \openout and \write I output text into a file. I want this file to have a name of containing an underscore (eg. name_01.txt), but I'm unable to get the underscore in the filename. My attempt (with \_):   \documentclass{article} \begin{document} \newwrite\tempfile \immediate\openout\tempfile="name\_01.txt" \immediate\write\tempfile{this is interesting} \immediate\closeout\tempfile \end{document}
114572
I want to rename all the files in a folder with PREFIX+COUNTER+FILENAME  for ex.  input:   england.txt   canada.txt   france.txt   output:    CO_01_england.txt   CO_02_canada.txt   CO_03_france.txt
25249
I realized I had named a bunch of files in an off-by-one fashion so I wanted to rename any file starting with "1" to the same thing except starting with 2.  For example mv 1.4.5.txt 2.4.5.txt or mv 1-chart.jpg 2-chart.jpg etc.  I tried mv 1* 2* but this was not accepted because it interprets 2* as a directory.