I made a for loop to save files in a directory but i would like the name of the file to start with zeros   this is the code that I made  for index, i in enumerate(list):      im = PImage.fromarray(i)      im.save(dir + '/' + 'data_' + str(index) +'.tiff')   And now the file names are   data_1.tiff   data_2.tiff  and so on   But I would like them to be   data_001.tiff  data_002.tiff
1551
What is a Pythonic way to pad a numeric string with zeroes to the left, i.e. so the numeric string has a specific length?
19937
I'm working on some scripting:  for x in `find ./ -name *.pdf` do   echo pathname $x done   My filenames are Test1 ( Volume II), Test2 ( Volume II). I'm getting a return of  pathname Test1 pathname ( pathname Volume pathname II …   How do I get it to stay as one variable?
78638
How can I iterate over each file in a directory using a for loop?  And how could I tell if a certain entry is a directory or if it's just a file?
46372
I'm looking for an algorithm that sorts strings similar to the way files (and folders) are sorted in Windows Explorer. It seems that numeric values in strings are taken into account when sorted which results in something like  name 1, name 2, name 10   instead of  name 1, name 10, name 2   which you get with a regular string comparison.  I was about to start writing this myself but wanted to check if anyone had done this before and was willing to share some code or insights. The way I would approach this would be to add leading zeros to the numeric values in the name before comparing them. This would result in something like  name 00001, name 00010, name 00002   which when sorted with a regular string sort would give me the correct result.  Any ideas?
85845
I am trying to copy multiple files named "F3.bam" two level of directories to up and then rename these files with the name of the sub-directory after copy.  For example:  /samples/mydata1/RUN1/ID_date/PCR2/TIME1/F3.bam /samples/mydata2/RUN1/ID2_date4/PCR2/TIME7/F3.bam /samples/mydataxxx/RUN1/IDxxx_datexxx/PCR2/TIMExxx/F3.bam   Expected results:  1. The files are first copied two directories level up:  /samples/mydata1/RUN1/ID_date/F3.bam /samples/mydata2/RUN1/ID2_date4/F3.bam /samples/mydataxxx/RUN1/IDxxx_datexxx/F3.bam   2. The files are renamed according to the name of the current sub-directory:  /samples/mydata1/RUN1/ID_date/ID_date_F3.bam /samples/mydata2/RUN1/ID2_date4/ID2_date4_F3.bam /samples/mydataxxx/RUN1/IDxxx_datexxx/IDxxx_datexxx_F3.bam   Ideally a bash loop would be great (working on a Mac).
74110
I am trying to rename a bunch of files according to the names of their directory in Linux, SSH.  I have a directory called XYZ01smith. In it are four files called smith_5*.I need to add prefix XYZ01 to these files. But, the next directory is called XYZ02perry. In it are four files called perry_3*. I need to add the prefix XYZ02 to these files.  I have a loop to do this per directory:  for i in smith_5*;     do mv ${i} XYZ01${i}; done    But I have 50 directories (XYZ01name to XYZ50name), so I would rather be able to do this with one script for all 50. I am sure this should be possible, but I do not know how.
41809
I have a string that I want to use as a filename, so I want to remove all characters that wouldn't be allowed in filenames, using Python.  I'd rather be strict than otherwise, so let's say I want to retain only letters, digits, and a small set of other characters like "_-.() ". What's the most elegant solution?  The filename needs to be valid on multiple operating systems (Windows, Linux and Mac OS) - it's an MP3 file in my library with the song title as the filename, and is shared and backed up between 3 machines.
29780
I am trying to convert a bunch of images to thumbnails that might be in several subdirectories, and save a copy of the image as a thumbnail inside the subdirectory, but I can't figure out the syntax. Any advice would be welcome.   convert test/*/*.jpg -50x50 test/*/*_thumb.jpg
3799
How do I access the index in a for loop like the following?  ints = [8, 23, 45, 12, 78] for i in ints:     print('item #{} = {}'.format(???, i))   I want to get this output:  item #1 = 8 item #2 = 23 item #3 = 45 item #4 = 12 item #5 = 78   When I loop through it using a for loop, how do I access the loop index, from 1 to 5 in this case?
81833
Just started reading a bit about the linux file system. In several places I found quotes like this one:      Unix directories are lists of association structures, each of which contains one filename and one inode number.   So I expected to find out that each directory would contain the names of the files under it, with each file mapped to an inode. But when I do vim directory_name in ubuntu, I get something like this:  " ============================================================================ " Netrw Directory Listing                                        (netrw v156) "   /Users/user/workspace/folder "   Sorted by      name "   Sort sequence: [\/]$,\&lt;core\%(\.\d\+\)\=\&gt;,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$ "   Quick Help: &lt;F1&gt;:help  -:go up dir  D:delete  R:rename  s:sort-by  x:special " ============================================================================== ../ ./ folder1/ folder2/ file1 file2   I expected to see an inode number next to each file name, why isn't this the case?
98998
I need to do create a file with a filename such as :&gt;?, is this possible somehow? Windows stops it.
41402
This may be a simple question, but how do I use files starting with "-" with command line programs?   For example,  I am trying to use pdfgrep on a file named -2013-01-01.pdf but it complains that there are no options defined for 2, 0, 1, 3 and so on.  Changing the filename to something that does not start with "-" solves it, but this is not an option since the files aren't created by me. I simply want to check for a specific change I know is coming.
86640
I have two questions. First, which command lists files and directories, but lists directories first?  Second question: I want to copy a list of files into a single directory, but make the target directory the first filename in the command.
97948
I'm assuming this is fairly easy to do, but I have zero experience with Windows's command line utilities. Basically, I need to iterate over all files in a directory (great if it can do sub-directories, but I can run it on each of the 5 directories if need be), get the name as a variable, and have it run   "C:\Program Files\ImageMagick-6.7.6-Q16\convert.exe" -compress LZW     -colorspace Gray -colors 32 file_var file_var   I saw . Would I be able to use that (swapping the SET... with the above command)? The space on the computer in question is beyond limited so I can't perform a backup prior to running this at this stage (bad, I know).
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}
51826
I am trying to loop through multiple rasters and extract cells that are above 0.1 The code I am trying to use is:  import arcpy  arcpy.CheckOutExtension('Spatial') arcpy.env.workspace=r'F:\Sheyenne\Atmospherically Corrected Landsat\Indices\Main\NDWI\main_master' #pathway to all rasters in workspace directory rasters = arcpy.ListRasters('*.tif*') for raster in rasters:      #give new file a name      outraster = raster.replace('.tif','_water.tif')      arcpy.gp.RasterCalculator_sa("""raster &gt;= 0.1""",outraster) print('Done Processing')   For some reason I can't copy and paste the error (python actually shuts down when I run this code) but here is a screen shot of part of it.    EDIT: My parameters have changed and I now need everything >=-0.4 and but !=0.00.  I am trying to use:  import arcpy  from arcpy.sa import * arcpy.CheckOutExtension('Spatial') arcpy.env.workspace=r'D:\Sheyenne\Atmospherically Corrected Landsat\Indices\Main\NDWI\main_master' #pathway to all rasters in workspace directory rasters = arcpy.ListRasters('*.tif*') for raster in rasters:     #Save temp raster to disk with new name     ras = Raster(raster)     outraster = Con(ras &gt;= -0.4 &amp; ras !=0.00, ras)     outraster.save(raster.replace('.tif','_water.tif')) print('Done Processing')   but this returns:  ValueError: The truth value of a raster is ambiguous. Invalid use of raster with Boolean operator or function. Check the use of parentheses where applicable.   EDIT:  I think I just needed to change this line:   outraster = Con((ras &gt;= -0.4) &amp; (ras !=0.00), ras)