DJango Error - [WinError 123] The filename, directory name, or volume label syntax is incorrect: '<frozen importlib._bootstrap>'
Found it. Instead of polls.url, I wrote poll.url inside the url.py for the mysite package. Watch your spelling!
How to solve OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect error in pycharm
The problem could be in your .urls especially if you were following the Django documentation, copying the code snippets and forgot to change the URL details to match your application settings.
In my case, for example, I had this:
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('crime_system/', include('polls.urls')),
path('admin/', admin.site.urls),
]
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: [Python]
I don't have a Windows box to try this on, but have you considered using os.path.join
to create paths?
basedir = os.path.join('C:/', 'Users', 'axeld', 'Desktop', 'Music', 'NG Trial')
old_name = os.path.join(basedir, item)
new_name = os.path.join(basedir, song_name)
os.rename(old_name, new_name)
From the documentation of os.path.join:
Join one or more path components intelligently. The return value is the concatenation of path and any members of *paths with exactly one directory separator (os.sep) following each non-empty part except the last, meaning that the result will only end in a separator if the last part is empty. If a component is an absolute path, all previous components are thrown away and joining continues from the absolute path component.
On Windows, the drive letter is not reset when an absolute path component (e.g., r'\foo') is encountered. If a component contains a drive letter, all previous components are thrown away and the drive letter is reset. Note that since there is a current directory for each drive, os.path.join("c:", "foo") represents a path relative to the current directory on drive C: (c:foo), not c:\foo.
Notice the very last line, which documents a special case on Windows (see also this answer on SO: that's why there's forward-slash after C:
in my code above.
Alternative solution
Based on the comments, the os.path.join
solution would still incur in errors.
As a workaround, you can use raw strings:
os.rename(
r'C:\Users\axeld\Desktop\Music\NG Trial\{}'.format(item),
r'C:\Users\axeld\Desktop\Music\NG Trial\{}'.format(song_name))
Related Topics
Extract Files from Zip File and Retain Mod Date
Modulenotfounderror: What Does It Mean _Main_ Is Not a Package
Pythonic Way to Check If Two Dictionaries Have the Identical Set of Keys
Split Data Directory into Training and Test Directory With Sub Directory Structure Preserved
How to Divide a Given Time Interval into Equal Intervals
How to Save Xlsm File With Macro, Using Openpyxl
How to Split Folder of Images into Test/Training/Validation Sets With Stratified Sampling
Django Login - Missing 1 Required Positional Argument
How to Change Border Color in Tkinter Widget
How to Find the Shortest Word in a List in Python
Python/Regex - How to Extract Date from Filename Using Regular Expression
Plot Line Graph from Pandas Dataframe (With Multiple Lines)
Drop Non-Numeric Columns from a Pandas Dataframe
Change Specific Value in CSV File Via Python
Set Working Directory in Python/Spyder So That It's Reproducible